killbill-kpm 0.0.5 → 0.1.0

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.
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
@@ -0,0 +1,68 @@
1
+ <div class="search">
2
+
3
+ <div class="column-block">
4
+
5
+ <h1>Configured instances</h1>
6
+
7
+ <div id="nodes-table-wrapper">
8
+ <%= render :partial => 'kpm/nodes_info/nodes_table', :locals => {:nodes_info => @nodes_info} %>
9
+ </div>
10
+
11
+ </div>
12
+
13
+ <div class="column-block">
14
+
15
+ <h1><%= link_to 'Install new plugin', plugins_path %></h1>
16
+
17
+ </div>
18
+
19
+ <div class="column-block">
20
+
21
+ <h1>Logs</h1>
22
+
23
+ <div id="logs-table-wrapper">
24
+ <%= render :partial => 'kpm/nodes_info/logs_table', :locals => {:logs => @logs} %>
25
+ </div>
26
+
27
+ </div>
28
+
29
+ </div>
30
+
31
+ <%= javascript_tag do %>
32
+ $(document).ready(function() {
33
+ scheduleRefresh();
34
+ });
35
+
36
+ function scheduleRefresh() {
37
+ var timer = setTimeout(refreshAll, 1500);
38
+
39
+ // Stop refreshing when user clicks through logs
40
+ $('#logs-table_wrapper a').one('click', function() {
41
+ clearTimeout(timer);
42
+ });
43
+
44
+ $('.plugin-link').one('ajax:beforeSend', function() {
45
+ // Disable the refresh
46
+ clearTimeout(timer);
47
+
48
+ // Prevent other clicks
49
+ $('.plugin-link').removeAttr('data-remote')
50
+ .removeAttr('data-method')
51
+ .removeAttr('href')
52
+
53
+ // Spin
54
+ $(this).children().addClass('fa-spin');
55
+ });
56
+
57
+ $('.plugin-link').one('ajax:complete', function() {
58
+ // Delay a bit, to give time for the plugin state to change before the next refresh
59
+ setTimeout(refreshAll, 6000);
60
+ });
61
+ }
62
+
63
+ function refreshAll() {
64
+ $.ajax({
65
+ url: "<%= nodes_info_index_path(:format => :js) %>"
66
+ });
67
+ }
68
+ <% end %>
@@ -0,0 +1,4 @@
1
+ $('#nodes-table-wrapper').html("<%= escape_javascript(render :partial => 'kpm/nodes_info/nodes_table', :locals => {:nodes_info => @nodes_info}) %>");
2
+ $('#logs-table-wrapper').html("<%= escape_javascript(render :partial => 'kpm/nodes_info/logs_table', :locals => {:logs => @logs}) %>");
3
+
4
+ scheduleRefresh();
@@ -0,0 +1,37 @@
1
+ <%= form_tag plugin_install_from_fs_path, :multipart => true, :class => 'form-horizontal' do %>
2
+ <div class="form-group">
3
+ <%= label_tag :key, 'Plugin key', :class => 'col-sm-2 control-label' %>
4
+ <div class="col-sm-9">
5
+ <%= text_field_tag :key, '', :class => 'form-control', :placeholder => 'Plugin key' %>
6
+ </div>
7
+ </div>
8
+ <div class="form-group">
9
+ <%= label_tag :version, 'Version', :class => 'col-sm-2 control-label' %>
10
+ <div class="col-sm-9">
11
+ <%= text_field_tag :version, '', :class => 'form-control', :placeholder => 'Plugin version' %>
12
+ </div>
13
+ </div>
14
+ <div class='form-group'>
15
+ <div class="col-sm-offset-2 col-sm-10">
16
+ <% %w(java ruby).each do |type| %>
17
+ <div class="checkbox">
18
+ <%= label_tag :type do %>
19
+ <%= radio_button_tag :type, type, (type == 'java') %>
20
+ <%= type %>
21
+ <% end %>
22
+ </div>
23
+ <% end %>
24
+ </div>
25
+ </div>
26
+ <div class="form-group">
27
+ <%= label_tag :plugin, 'Plugin', :class => 'col-sm-2 control-label' %>
28
+ <div class="col-sm-10">
29
+ <%= file_field_tag 'plugin', :class => 'form-control' %>
30
+ </div>
31
+ </div>
32
+ <div class="form-group">
33
+ <div class="col-sm-offset-2 col-sm-10">
34
+ <%= submit_tag 'Install', :class => 'btn btn-default' %>
35
+ </div>
36
+ </div>
37
+ <% end %>
@@ -0,0 +1,48 @@
1
+ <table id="plugins-table" class="table table-condensed table-striped mobile-data">
2
+ <thead>
3
+ <tr>
4
+ <th>Name</th>
5
+ <th>Type</th>
6
+ <th>Versions</th>
7
+ <th>Required configuration</th>
8
+ <th></th>
9
+ </tr>
10
+ </thead>
11
+ <tbody>
12
+ <% plugins.each do |name, details| %>
13
+ <tr>
14
+ <td><%= name %></td>
15
+ <td><%= details['type'] %></td>
16
+ <td>
17
+ <% unless details['versions'].nil? %>
18
+ <ul>
19
+ <% details['versions'].each do |kb_version, plugin_version| %>
20
+ <li><%= kb_version %>: <%= plugin_version %></li>
21
+ <% end %>
22
+ </ul>
23
+ <% end %>
24
+ </td>
25
+ <td>
26
+ <% unless (details['require'] || []).empty? %>
27
+ <ul>
28
+ <% details['require'].each do |property| %>
29
+ <li><%= property %></li>
30
+ <% end %>
31
+ </ul>
32
+ <% end %>
33
+ </td>
34
+ <td><%= link_to '<i class="fa fa-cloud-download"></i>'.html_safe, plugin_install_path(:plugin_key => name), :method => :post, :title => 'Install' %></td>
35
+ </tr>
36
+ <% end %>
37
+ </tbody>
38
+ </table>
39
+
40
+ <%= javascript_tag do %>
41
+ $(document).ready(function() {
42
+ $('#plugins-table').dataTable({
43
+ "dom": "t",
44
+ "paging": false,
45
+ "ordering": false
46
+ });
47
+ });
48
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <div class="search">
2
+
3
+ <div class="column-block">
4
+
5
+ <h1>Available plugins</h1>
6
+
7
+ <%= render :partial => 'kpm/plugins/plugins_table', :locals => {:plugins => @plugins} %>
8
+
9
+ </div>
10
+
11
+ <div class="column-block">
12
+
13
+ <h1>Upload plugin</h1>
14
+ <%= render 'form' %>
15
+
16
+ </div>
17
+
18
+ </div>
data/config/routes.rb ADDED
@@ -0,0 +1,17 @@
1
+ KPM::Engine.routes.draw do
2
+
3
+ root to: 'nodes_info#index'
4
+
5
+ resources :nodes_info, :only => [:index]
6
+ resources :plugins, :only => [:index]
7
+
8
+ scope '/nodes_info' do
9
+ match '/plugin/install' => 'nodes_info#install_plugin', :via => :post, :as => 'plugin_install'
10
+ match '/plugin/install_from_fs' => 'nodes_info#install_plugin_from_fs', :via => :post, :as => 'plugin_install_from_fs'
11
+ match '/plugin/uninstall' => 'nodes_info#uninstall_plugin', :via => :post, :as => 'plugin_uninstall'
12
+ match '/plugin/start' => 'nodes_info#start_plugin', :via => :post, :as => 'plugin_start'
13
+ match '/plugin/stop' => 'nodes_info#stop_plugin', :via => :post, :as => 'plugin_stop'
14
+ match '/plugin/restart' => 'nodes_info#restart_plugin', :via => :post, :as => 'plugin_restart'
15
+ end
16
+
17
+ end
data/lib/kpm.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'kpm/engine'
2
+
3
+ module KPM
4
+
5
+ mattr_accessor :current_tenant_user
6
+ mattr_accessor :layout
7
+
8
+ self.current_tenant_user = lambda { |session, user|
9
+ {
10
+ :username => 'admin',
11
+ :password => 'password',
12
+ :session_id => nil,
13
+ :api_key => KillBillClient.api_key,
14
+ :api_secret => KillBillClient.api_secret
15
+ }
16
+ }
17
+
18
+ def self.config(&block)
19
+ {
20
+ :layout => layout || 'kpm/layouts/kpm_application',
21
+ }
22
+ end
23
+
24
+ end
data/lib/kpm/client.rb ADDED
@@ -0,0 +1,31 @@
1
+ module Killbill
2
+ module KPM
3
+
4
+ class KPMClient < KillBillClient::Model::Resource
5
+
6
+ KILLBILL_KPM_PREFIX = '/plugins/killbill-kpm'
7
+ KILLBILL_OSGI_LOGGER_PREFIX = '/plugins/killbill-osgi-logger'
8
+
9
+ class << self
10
+
11
+ def get_available_plugins(latest=true, options = {})
12
+ path = "#{KILLBILL_KPM_PREFIX}/plugins"
13
+ response = KillBillClient::API.get path, { :latest => latest }, options
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ def get_osgi_logs(options = {})
18
+ response = KillBillClient::API.get KILLBILL_OSGI_LOGGER_PREFIX, {}, options
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def install_plugin(key, version, type, filename, plugin, options = {})
23
+ path = "#{KILLBILL_KPM_PREFIX}/plugins"
24
+ KillBillClient::API.post path, plugin, {:key => key, :version => version, :type => type, :filename => filename}, options.merge(:content_type => 'application/octet-stream')
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
data/lib/kpm/engine.rb ADDED
@@ -0,0 +1,23 @@
1
+ # Dependencies
2
+ #
3
+ # Sigh. Rails autoloads the gems specified in the Gemfile and nothing else.
4
+ # We need to explicitly require all of our dependencies listed in kpm.gemspec
5
+ #
6
+ # See also https://github.com/carlhuda/bundler/issues/49
7
+ require 'jquery-rails'
8
+ require 'jquery-datatables-rails'
9
+ require 'bootstrap-datepicker-rails'
10
+ require 'd3_rails'
11
+ require 'momentjs-rails'
12
+ require 'spinjs-rails'
13
+ require 'killbill_client'
14
+
15
+ module KPM
16
+ class Engine < ::Rails::Engine
17
+ isolate_namespace KPM
18
+
19
+ ActiveSupport::Inflector.inflections do |inflect|
20
+ inflect.acronym 'KPM'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module KPM
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :kpm do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "kpm"
7
+
8
+ require "jquery-rails"
9
+ require "twitter-bootstrap-rails"
10
+ require "d3_rails"
11
+
12
+ require "js-routes"
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
21
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
22
+ # config.time_zone = 'Central Time (US & Canada)'
23
+
24
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
+ # config.i18n.default_locale = :de
27
+
28
+ # Do not swallow errors in after_commit/after_rollback callbacks.
29
+ config.active_record.raise_in_transactional_callbacks = true
30
+ end
31
+ end
32
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,23 @@
1
+ # SQLite version 3.x
2
+ # gem 'activerecord-jdbcsqlite3-adapter'
3
+ #
4
+ # Configure Using Gemfile
5
+ # gem 'activerecord-jdbcsqlite3-adapter'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+
10
+ development:
11
+ <<: *default
12
+ database: db/development.sqlite3
13
+
14
+ # Warning: The database defined as "test" will be erased and
15
+ # re-generated from your development database when you run "rake".
16
+ # Do not set this db to the same as development or production.
17
+ test:
18
+ <<: *default
19
+ database: db/test.sqlite3
20
+
21
+ production:
22
+ <<: *default
23
+ database: db/production.sqlite3