killbill-kpm-ui 1.0.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 (63) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +32 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/application.js +18 -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 +13 -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 +21 -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 +38 -0
  36. data/test/dummy/bin/update +29 -0
  37. data/test/dummy/bin/yarn +11 -0
  38. data/test/dummy/config.ru +4 -0
  39. data/test/dummy/config/application.rb +26 -0
  40. data/test/dummy/config/boot.rb +3 -0
  41. data/test/dummy/config/environment.rb +5 -0
  42. data/test/dummy/config/environments/development.rb +54 -0
  43. data/test/dummy/config/environments/production.rb +91 -0
  44. data/test/dummy/config/environments/test.rb +42 -0
  45. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  46. data/test/dummy/config/initializers/assets.rb +14 -0
  47. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  49. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/test/dummy/config/initializers/inflections.rb +16 -0
  51. data/test/dummy/config/initializers/killbill_client.rb +3 -0
  52. data/test/dummy/config/initializers/mime_types.rb +4 -0
  53. data/test/dummy/config/initializers/new_framework_defaults_5_1.rb +14 -0
  54. data/test/dummy/config/initializers/session_store.rb +3 -0
  55. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  56. data/test/dummy/config/locales/en.yml +33 -0
  57. data/test/dummy/config/routes.rb +4 -0
  58. data/test/dummy/config/secrets.yml +32 -0
  59. data/test/dummy/log/test.log +21 -0
  60. data/test/integration/navigation_test.rb +17 -0
  61. data/test/kpm_test.rb +8 -0
  62. data/test/test_helper.rb +19 -0
  63. metadata +279 -0
@@ -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,21 @@
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 'font-awesome-rails'
10
+ require 'twitter-bootstrap-rails'
11
+ require 'killbill_client'
12
+
13
+ module KPM
14
+ class Engine < ::Rails::Engine
15
+ isolate_namespace KPM
16
+
17
+ ActiveSupport::Inflector.inflections do |inflect|
18
+ inflect.acronym 'KPM'
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module KPM
2
+ VERSION = '1.0.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', __dir__)
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,38 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a starting point to setup your application.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ # Install JavaScript dependencies if using Yarn
22
+ # system('bin/yarn')
23
+
24
+
25
+ # puts "\n== Copying sample files =="
26
+ # unless File.exist?('config/database.yml')
27
+ # cp 'config/database.yml.sample', 'config/database.yml'
28
+ # end
29
+
30
+ puts "\n== Preparing database =="
31
+ system! 'bin/rails db:setup'
32
+
33
+ puts "\n== Removing old logs and tempfiles =="
34
+ system! 'bin/rails log:clear tmp:clear'
35
+
36
+ puts "\n== Restarting application server =="
37
+ system! 'bin/rails restart'
38
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a way to update your development environment automatically.
15
+ # Add necessary update steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ puts "\n== Updating database =="
22
+ system! 'bin/rails db:migrate'
23
+
24
+ puts "\n== Removing old logs and tempfiles =="
25
+ system! 'bin/rails log:clear tmp:clear'
26
+
27
+ puts "\n== Restarting application server =="
28
+ system! 'bin/rails restart'
29
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ VENDOR_PATH = File.expand_path('..', __dir__)
3
+ Dir.chdir(VENDOR_PATH) do
4
+ begin
5
+ exec "yarnpkg #{ARGV.join(" ")}"
6
+ rescue Errno::ENOENT
7
+ $stderr.puts "Yarn executable was not detected in the system."
8
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9
+ exit 1
10
+ end
11
+ end