killbill-kpm 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +2 -2
  4. data/Rakefile +31 -16
  5. data/app/assets/javascripts/application.js +24 -0
  6. data/app/assets/javascripts/kpm/kpm.js +7 -0
  7. data/app/assets/stylesheets/application.css +19 -0
  8. data/app/assets/stylesheets/bootstrap_and_overrides.css +17 -0
  9. data/app/assets/stylesheets/kpm/kpm.css +6 -0
  10. data/app/controllers/kpm/engine_controller.rb +29 -0
  11. data/app/controllers/kpm/nodes_info_controller.rb +109 -0
  12. data/app/controllers/kpm/plugins_controller.rb +19 -0
  13. data/app/helpers/kpm/application_helper.rb +4 -0
  14. data/app/views/kpm/layouts/kpm_application.html.erb +31 -0
  15. data/app/views/kpm/nodes_info/_logs_table.html.erb +43 -0
  16. data/app/views/kpm/nodes_info/_nodes_table.html.erb +68 -0
  17. data/app/views/kpm/nodes_info/index.html.erb +68 -0
  18. data/app/views/kpm/nodes_info/index.js.erb +4 -0
  19. data/app/views/kpm/plugins/_form.html.erb +37 -0
  20. data/app/views/kpm/plugins/_plugins_table.html.erb +48 -0
  21. data/app/views/kpm/plugins/index.html.erb +18 -0
  22. data/config/routes.rb +17 -0
  23. data/lib/kpm.rb +24 -0
  24. data/lib/kpm/client.rb +31 -0
  25. data/lib/kpm/engine.rb +23 -0
  26. data/lib/kpm/version.rb +3 -0
  27. data/lib/tasks/kpm_tasks.rake +4 -0
  28. data/test/dummy/README.rdoc +28 -0
  29. data/test/dummy/Rakefile +6 -0
  30. data/test/dummy/app/controllers/application_controller.rb +5 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/bin/bundle +3 -0
  33. data/test/dummy/bin/rails +4 -0
  34. data/test/dummy/bin/rake +4 -0
  35. data/test/dummy/bin/setup +29 -0
  36. data/test/dummy/config.ru +4 -0
  37. data/test/dummy/config/application.rb +32 -0
  38. data/test/dummy/config/boot.rb +5 -0
  39. data/test/dummy/config/database.yml +23 -0
  40. data/test/dummy/config/environment.rb +5 -0
  41. data/test/dummy/config/environments/development.rb +41 -0
  42. data/test/dummy/config/environments/production.rb +79 -0
  43. data/test/dummy/config/environments/test.rb +42 -0
  44. data/test/dummy/config/initializers/assets.rb +11 -0
  45. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  47. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/test/dummy/config/initializers/inflections.rb +16 -0
  49. data/test/dummy/config/initializers/killbill_client.rb +3 -0
  50. data/test/dummy/config/initializers/mime_types.rb +4 -0
  51. data/test/dummy/config/initializers/session_store.rb +3 -0
  52. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  53. data/test/dummy/config/locales/en.yml +23 -0
  54. data/test/dummy/config/routes.rb +4 -0
  55. data/test/dummy/config/secrets.yml +22 -0
  56. data/test/integration/navigation_test.rb +8 -0
  57. data/test/kpm_test.rb +7 -0
  58. data/test/test_helper.rb +21 -0
  59. metadata +349 -49
  60. data/.gitignore +0 -33
  61. data/.travis.yml +0 -41
  62. data/Gemfile +0 -5
  63. data/Gemfile.head +0 -5
  64. data/Gemfile.lock +0 -109
  65. data/Jarfile +0 -11
  66. data/Jarfile.lock +0 -61
  67. data/LICENSE +0 -201
  68. data/VERSION +0 -1
  69. data/config.ru +0 -4
  70. data/killbill-kpm.gemspec +0 -31
  71. data/killbill.properties +0 -3
  72. data/lib/kpm/application.rb +0 -92
  73. data/lib/kpm/listener.rb +0 -94
  74. data/lib/kpm/plugins_installer.rb +0 -112
  75. data/lib/kpm_plugin.rb +0 -13
  76. data/pom.xml +0 -44
  77. data/release.sh +0 -61
  78. data/spec/kpm/base_plugin_spec.rb +0 -25
  79. data/spec/spec_helper.rb +0 -14
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.5
data/config.ru DELETED
@@ -1,4 +0,0 @@
1
- require 'kpm_plugin'
2
- require 'kpm/application'
3
-
4
- run Sinatra::Application
data/killbill-kpm.gemspec DELETED
@@ -1,31 +0,0 @@
1
- version = File.read(File.expand_path('../VERSION', __FILE__)).strip
2
-
3
- Gem::Specification.new do |s|
4
- s.name = 'killbill-kpm'
5
- s.version = version
6
- s.summary = 'Kill Bill KPM plugin'
7
- s.description = 'Plugin to manage installed plugins'
8
-
9
- s.required_ruby_version = '>= 1.9.3'
10
-
11
- s.license = 'Apache License (2.0)'
12
-
13
- s.author = 'Killbill core team'
14
- s.email = 'killbilling-users@googlegroups.com'
15
- s.homepage = 'http://killbill.io'
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.bindir = 'bin'
20
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
- s.require_paths = ['lib']
22
-
23
- s.rdoc_options << '--exclude' << '.'
24
-
25
- s.add_dependency 'killbill', '~> 7.0'
26
- s.add_dependency 'kpm', '~> 0.1.4'
27
-
28
- s.add_development_dependency 'jbundler', '~> 0.9.2'
29
- s.add_development_dependency 'rake', '>= 10.0.0'
30
- s.add_development_dependency 'rspec', '~> 2.12.0'
31
- end
data/killbill.properties DELETED
@@ -1,3 +0,0 @@
1
- mainClass=KPM::Listener
2
- require=kpm_plugin
3
- pluginType=NOTIFICATION
@@ -1,92 +0,0 @@
1
- configure do
2
- # Usage: bundle exec rackup -Ilib -E test
3
- if development? or test?
4
- require 'logger'
5
- ::KPM::PluginsInstaller.instance.initialize!('/var/tmp/bundles/plugins/ruby/kpm/0.0.1',
6
- File.expand_path(File.dirname(__FILE__) + '../../../'),
7
- nil,
8
- Logger.new(STDOUT))
9
- end
10
- end
11
-
12
- # Lookup plugins
13
- get '/plugins/killbill-kpm/plugins', :provides => 'json' do
14
- artifact_id = params[:artifact_id] || params[:name]
15
- latest = params[:latest] == 'false' ? false : true
16
-
17
- if artifact_id.nil?
18
- ::KPM::PluginsInstaller.instance.all(latest).to_json
19
- else
20
- group_id, artifact_id, packaging, classifier, version, type = ::KPM::PluginsInstaller.instance.lookup artifact_id, latest
21
-
22
- if artifact_id.nil?
23
- status 404
24
- else
25
- {
26
- :group_id => group_id,
27
- :artifact_id => artifact_id,
28
- :packaging => packaging,
29
- :classifier => classifier,
30
- :version => version,
31
- :type => type
32
- }.to_json
33
- end
34
- end
35
- end
36
-
37
- # Install a plugin
38
- post '/plugins/killbill-kpm/plugins', :provides => 'json' do
39
- if !request.body.nil?
40
- type = (params[:type] || 'java').downcase
41
-
42
- info = Dir.mktmpdir do |dir|
43
- plugin_path = File.join(dir, params[:filename] || "#{params[:name]}.#{type == 'java' ? 'jar' : 'tar.gz'}")
44
- File.open(plugin_path, 'w') do |file|
45
- file.write(request.body.read)
46
- end
47
- ::KPM::PluginsInstaller.instance.install_from_fs params[:key],
48
- plugin_path,
49
- params[:version],
50
- type
51
- end
52
- else
53
- info = ::KPM::PluginsInstaller.instance.install params[:key],
54
- params[:artifact_id],
55
- params[:version],
56
- params[:group_id],
57
- params[:packaging],
58
- params[:classifier],
59
- params[:type],
60
- params[:force_download]
61
- end
62
-
63
- if info.nil?
64
- status 400
65
- else
66
- info.to_json
67
- end
68
- end
69
-
70
- # Uninstall a plugin
71
- delete '/plugins/killbill-kpm/plugins', :provides => 'json' do
72
- modified = ::KPM::PluginsInstaller.instance.uninstall params[:key],
73
- params[:version]
74
-
75
- if modified.empty?
76
- status 404
77
- else
78
- modified.to_json
79
- end
80
- end
81
-
82
- # Restart a plugin
83
- put '/plugins/killbill-kpm/plugins', :provides => 'json' do
84
- modified = ::KPM::PluginsInstaller.instance.restart params[:key],
85
- params[:version]
86
-
87
- if modified.empty?
88
- status 404
89
- else
90
- modified.to_json
91
- end
92
- end
data/lib/kpm/listener.rb DELETED
@@ -1,94 +0,0 @@
1
- require 'nexus_cli'
2
-
3
- module KPM
4
- class Listener < Killbill::Plugin::Notification
5
-
6
-
7
- def start_plugin
8
- super
9
- ::KPM::PluginsInstaller.instance.initialize!(@root, @conf_dir, @kb_apis, @logger)
10
- # We don't know yet
11
- @kb_version = nil
12
- end
13
-
14
- def on_event(event)
15
-
16
- return unless [:BROADCAST_SERVICE].include?(event.event_type)
17
-
18
- unless ::KPM::PluginsInstaller.instance.initialized?
19
- @logger.warn "KPM plugin wasn't started properly - check logs"
20
- return
21
- end
22
-
23
- broadcast_metadata = event.meta_data.nil? ? {} : JSON.parse(event.meta_data)
24
- command = broadcast_metadata['commandType']
25
- return if command != 'INSTALL_PLUGIN' && command != 'UNINSTALL_PLUGIN'
26
-
27
- service = broadcast_metadata['service']
28
- event_json = broadcast_metadata['eventJson'].nil? ? {} : JSON.parse(broadcast_metadata['eventJson'])
29
-
30
- properties = properties_to_hash(event_json['properties'])
31
-
32
- @logger.info "Received #{event.event_type} event: service=#{service} command=#{command} event=#{event_json}"
33
-
34
- # pluginKey is the only mandatory property
35
- if event_json['pluginKey'].nil?
36
- @logger.info("Cannot run #{command}: missing pluginKey property")
37
- return false
38
- end
39
-
40
- handle_event(command,
41
- event_json['pluginKey'],
42
- properties['pluginArtifactId'],
43
- event_json['pluginVersion'],
44
- properties['pluginGroupId'],
45
- properties['pluginPackaging'],
46
- properties['pluginClassifier'],
47
- properties['pluginType'],
48
- properties['forceDownload'] == 'true')
49
- end
50
-
51
- private
52
-
53
- def get_kb_version
54
- return @kb_version if @kb_version
55
-
56
- nodes_info = @kb_apis.killbill_nodes_api.get_nodes_info
57
- if nodes_info.nil? || nodes_info.empty?
58
- @logger.warn("Unable to retrieve node info")
59
- end
60
-
61
- # This is incorrect, we need to find the entry for our node, but we don't seem to know who we are -:(
62
- # (The will break in rolling upgrade scenario)
63
- @kb_version = nodes_info[0].killbill_version
64
-
65
- @logger.info("KPM plugin extracted killbill version #{@kb_version}")
66
-
67
- @kb_version
68
- end
69
-
70
- def handle_event(command, plugin_key, artifact_id, version=nil, group_id=nil, packaging=nil, classifier=nil, type=nil, force_download=false)
71
- @logger.info "handle_event command=#{command}, plugin_key=#{plugin_key}, artifact_id=#{artifact_id}, version=#{version}, group_id=#{group_id}, packaging=#{packaging}, classifier=#{classifier}, type=#{type}, force_download=#{force_download}"
72
-
73
- if command == 'INSTALL_PLUGIN'
74
- ::KPM::PluginsInstaller.instance.install(plugin_key, get_kb_version, artifact_id, version, group_id, packaging, classifier, type, force_download)
75
- elsif command == 'UNINSTALL_PLUGIN'
76
- ::KPM::PluginsInstaller.instance.uninstall(plugin_key, version)
77
- else
78
- @logger.warn("Ignoring unsupported command #{command}")
79
- end
80
- rescue NexusCli::ArtifactNotFoundException
81
- @logger.warn("Unable to #{command} for plugin_key=#{plugin_key}: artifact was not found in Nexus")
82
- end
83
-
84
- def properties_to_hash(properties)
85
- return {} if properties.nil?
86
-
87
- h = {}
88
- properties.each do |prop|
89
- h[prop['key']] = prop['value']
90
- end
91
- h
92
- end
93
- end
94
- end
@@ -1,112 +0,0 @@
1
- module KPM
2
- class PluginsInstaller
3
- include Singleton
4
-
5
- attr_reader :initialized
6
- alias_method :initialized?, :initialized
7
-
8
- def initialize!(root_dir, conf_dir, kb_apis, logger)
9
- @kb_apis = kb_apis
10
- @logger = logger
11
-
12
- configure!(Pathname.new(conf_dir).expand_path.join('kpm.yml'))
13
-
14
- @bundles_dir = Pathname.new(root_dir).join('..').join('..').join('..').join('..').expand_path
15
- plugins_dir = @bundles_dir.join('plugins')
16
-
17
- @installer = ::KPM::BaseInstaller.new(@logger, @glob_config[:kpm][:nexus], @glob_config[:kpm][:ssl_verify])
18
- @manager = ::KPM::PluginsManager.new(plugins_dir, @logger)
19
-
20
- @initialized = true
21
- end
22
-
23
- # If an earlier version of the plugin is installed, Kill Bill will only start the latest one (see org.killbill.billing.osgi.FileInstall)
24
- def install(plugin_key, kb_version, specified_artifact_id, specified_version=nil, specified_group_id=nil, specified_packaging=nil, specified_classifier=nil, specified_type=nil, force_download=false)
25
- @logger.info("Instructed to install plugin_key=#{plugin_key} artifact_id=#{specified_artifact_id} version=#{specified_version} group_id=#{specified_group_id} packaging=#{specified_packaging} classifier=#{specified_classifier} type=#{specified_type} force_download=#{force_download}")
26
- info = @installer.install_plugin(plugin_key, kb_version, specified_group_id, specified_artifact_id, specified_packaging, specified_classifier, specified_version, @bundles_dir, specified_type, force_download, @glob_config[:kpm][:verify_sha1])
27
- if info.nil?
28
- @logger.warn("Error during installation of plugin #{specified_artifact_id}")
29
- else
30
- path = info[:bundle_dir]
31
- notify_fs_change(plugin_key, path, :NEW_VERSION)
32
- end
33
- info
34
- end
35
-
36
- def install_from_fs(plugin_key, file_path, version, type)
37
- @logger.info("Instructed to install file_path=#{file_path} plugin_key=#{plugin_key} version=#{version} type=#{type}")
38
- info = @installer.install_plugin_from_fs(plugin_key, file_path, plugin_key, version, @bundles_dir, type)
39
- if info.nil?
40
- @logger.warn("Error during installation of plugin #{plugin_key}")
41
- else
42
- path = info[:bundle_dir] || info[:dir_name]
43
- notify_fs_change(plugin_key, path, :NEW_VERSION)
44
- end
45
- info
46
- end
47
-
48
- def uninstall(plugin_key, version=nil)
49
- modified = @installer.uninstall_plugin(plugin_key, version || :all, @bundles_dir)
50
- modified.each do |path|
51
- notify_fs_change(plugin_key, path, :DISABLED)
52
- end
53
- end
54
-
55
- def restart(plugin_name, version=nil)
56
- @manager.restart(plugin_name, version || :all)
57
- end
58
-
59
- def lookup(artifact_id, latest=true)
60
- KPM::PluginsDirectory.lookup(artifact_id, latest)
61
- end
62
-
63
- def all(latest=true)
64
- KPM::PluginsDirectory.all(latest)
65
- end
66
-
67
- private
68
-
69
- def notify_fs_change(plugin_key, path, state)
70
- return if path.nil?
71
-
72
- @logger.info("notify_fs_change: plugin_key = #{plugin_key}, path=#{path}, state=#{state}")
73
-
74
- # Plugin name should be the directory name (path is something like /var/tmp/bundles/plugins/ruby/killbill-stripe/2.0.0 or /var/tmp/bundles/plugins/ruby)
75
- fs_info = path.to_s.split('/')
76
- plugin_type = fs_info[-3].upcase
77
- plugin_name = fs_info[-2]
78
- plugin_version = fs_info[-1]
79
-
80
-
81
- if @kb_apis.nil?
82
- @logger.warn("APIs not configured: Kill Bill won't be notified of new state #{state}")
83
- return
84
- end
85
-
86
- @logger.info("Notifying Kill Bill: state=#{state} plugin_key=#{plugin_key} plugin_name=#{plugin_name} plugin_version=#{plugin_version} plugin_type=#{plugin_type}")
87
- @kb_apis.plugins_info_api.notify_of_state_changed(state, plugin_key, plugin_name, plugin_version, plugin_type)
88
- end
89
-
90
- def configure!(config_file)
91
- @glob_config = {}
92
-
93
- # Look for global config
94
- if !config_file.blank? && Pathname.new(config_file).file?
95
- @glob_config = ::Killbill::Plugin::ActiveMerchant::Properties.new(config_file)
96
- @glob_config.parse!
97
- @glob_config = @glob_config.to_hash
98
- end
99
-
100
- @glob_config[:kpm] ||= {}
101
-
102
- @glob_config[:kpm][:nexus] ||= {}
103
- @glob_config[:kpm][:nexus][:url] ||= 'https://oss.sonatype.org'
104
- @glob_config[:kpm][:nexus][:repository] ||= 'releases'
105
-
106
- @glob_config[:kpm][:ssl_verify] = true if @glob_config[:kpm][:ssl_verify].nil?
107
- @glob_config[:kpm][:verify_sha1] = true if @glob_config[:kpm][:verify_sha1].nil?
108
-
109
- @logger.level = Logger::DEBUG if (@glob_config[:logger] || {})[:debug]
110
- end
111
- end
112
- end
data/lib/kpm_plugin.rb DELETED
@@ -1,13 +0,0 @@
1
- require 'active_support/core_ext/object/blank'
2
- require 'json'
3
- require 'pathname'
4
- require 'sinatra'
5
- require 'yaml'
6
-
7
- require 'kpm'
8
-
9
- require 'killbill'
10
- require 'killbill/helpers/active_merchant/properties'
11
-
12
- require 'kpm/plugins_installer'
13
- require 'kpm/listener'
data/pom.xml DELETED
@@ -1,44 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!--
3
- ~ Copyright 2014-2015 The Billing Project, LLC
4
- ~
5
- ~ The Billing Project licenses this file to you under the Apache License, version 2.0
6
- ~ (the "License"); you may not use this file except in compliance with the
7
- ~ License. You may obtain a copy of the License at:
8
- ~
9
- ~ http://www.apache.org/licenses/LICENSE-2.0
10
- ~
11
- ~ Unless required by applicable law or agreed to in writing, software
12
- ~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- ~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
- ~ License for the specific language governing permissions and limitations
15
- ~ under the License.
16
- -->
17
-
18
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
19
- <parent>
20
- <groupId>org.sonatype.oss</groupId>
21
- <artifactId>oss-parent</artifactId>
22
- <version>5</version>
23
- </parent>
24
- <modelVersion>4.0.0</modelVersion>
25
- <groupId>org.kill-bill.billing.plugin.ruby</groupId>
26
- <artifactId>kpm-plugin</artifactId>
27
- <packaging>pom</packaging>
28
- <version>0.0.5</version>
29
- <name>kpm-plugin</name>
30
- <url>http://github.com/killbill/killbill-kpm-plugin</url>
31
- <description>Kill Bill KPM plugin</description>
32
- <licenses>
33
- <license>
34
- <name>Apache License 2.0</name>
35
- <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
36
- <distribution>repo</distribution>
37
- </license>
38
- </licenses>
39
- <scm>
40
- <connection>scm:git:git://github.com/killbill/killbill-kpm-plugin.git</connection>
41
- <url>https://github.com/killbill/killbill-kpm-plugin/</url>
42
- <developerConnection>scm:git:git@github.com:killbill/killbill-kpm-plugin.git</developerConnection>
43
- </scm>
44
- </project>
data/release.sh DELETED
@@ -1,61 +0,0 @@
1
- set -e
2
-
3
- BUNDLE=${BUNDLE-"bundle exec"}
4
- MVN=${MVN-"mvn"}
5
-
6
- if [ 'GNU' != "$(tar --help | grep GNU | head -1 | awk '{print $1}')" ]; then
7
- echo 'Unable to release: make sure to use GNU tar'
8
- exit 1
9
- fi
10
-
11
- if $(ruby -e'require "java"'); then
12
- # Good
13
- echo 'Detected JRuby'
14
- else
15
- echo 'Unable to release: make sure to use JRuby'
16
- exit 1
17
- fi
18
-
19
- VERSION=`grep -E '<version>([0-9]+\.[0-9]+\.[0-9]+)</version>' pom.xml | sed 's/[\t \n]*<version>\(.*\)<\/version>[\t \n]*/\1/'`
20
- if [[ -z "$NO_RELEASE" && "$VERSION" != "$(cat $PWD/VERSION)" ]]; then
21
- echo 'Unable to release: make sure the versions in pom.xml and VERSION match'
22
- exit 1
23
- fi
24
-
25
- echo 'Cleaning up'
26
- $BUNDLE rake killbill:clean
27
-
28
- echo 'Building gem'
29
- $BUNDLE rake build
30
-
31
- if [[ -z "$NO_RELEASE" ]]; then
32
- echo 'Pushing the gem to Rubygems'
33
- $BUNDLE rake release
34
- fi
35
-
36
- echo 'Building artifact'
37
- $BUNDLE rake killbill:package
38
-
39
- ARTIFACT="$PWD/pkg/killbill-kpm-$VERSION.tar.gz"
40
- echo "Pushing $ARTIFACT to Maven Central"
41
-
42
- if [[ -z "$NO_RELEASE" ]]; then
43
- GOAL=gpg:sign-and-deploy-file
44
- REPOSITORY_ID=ossrh-releases
45
- URL=https://oss.sonatype.org/service/local/staging/deploy/maven2/
46
- else
47
- GOAL=deploy:deploy-file
48
- REPOSITORY_ID=sonatype-nexus-snapshots
49
- URL=https://oss.sonatype.org/content/repositories/snapshots/
50
- VERSION="$VERSION-SNAPSHOT"
51
- fi
52
-
53
- $MVN $GOAL \
54
- -DgroupId=org.kill-bill.billing.plugin.ruby \
55
- -DartifactId=kpm-plugin \
56
- -Dversion=$VERSION \
57
- -Dpackaging=tar.gz \
58
- -DrepositoryId=$REPOSITORY_ID \
59
- -Durl=$URL \
60
- -Dfile=$ARTIFACT \
61
- -DpomFile=pom.xml