killbill-kpm-ui 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c7ab1958f7682e1709819cb222d376118b0df25
4
+ data.tar.gz: 5bcb62502ce425428aafcd7c7f8b836e7b8fd0be
5
+ SHA512:
6
+ metadata.gz: d2c0cc082907faa196de41f2ee58e179a28706ad22013b667f3ee0e060d2da7ddcf2deadb18a5595b9bbae45426937159910e013beb07f82b97e76bc01d7dae6
7
+ data.tar.gz: 8f4d5ef2d2f24785759cb223d419758e7c8f246f39e9ecf62de1226870945bc7bf3c38e203e8d46fc6f9045e6c5f14732927ae433fdb43ac30d54f2cc7ba606e
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 The Billing Project, LLC
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.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ Overview
2
+ ========
3
+
4
+ Rails mountable engine to manage the KPM plugin.
5
+
6
+ See [killbill-admin-ui-standalone](https://github.com/killbill/killbill-admin-ui-standalone) to get started with the Kill Bill Admin UI.
7
+
8
+ Kill Bill compatibility
9
+ -----------------------
10
+
11
+ | KPM UI version | Kill Bill version |
12
+ | -------------: | ----------------: |
13
+ | 0.1.y | 0.16.z |
14
+ | 0.2.y | 0.18.z (Rails 4) |
15
+ | 0.3.y | 0.18.z (Rails 5) |
16
+ | 1.x.y | 0.19.z |
17
+
18
+ Testing
19
+ -------
20
+
21
+ To run the dummy app:
22
+
23
+ ```
24
+ rails s
25
+ ```
26
+
27
+
28
+ To run tests:
29
+
30
+ ```
31
+ rails t
32
+ ```
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'KPM'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,18 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require twitter/bootstrap
16
+ //= require dataTables/jquery.dataTables
17
+ //= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
18
+ //= require kpm/kpm
@@ -0,0 +1,7 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require_tree .
@@ -0,0 +1,19 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_self
14
+ *= require dataTables/jquery.dataTables
15
+ *= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
16
+ *= require font-awesome
17
+ *= require bootstrap_and_overrides
18
+ *= require kpm/kpm
19
+ */
@@ -0,0 +1,13 @@
1
+ /*
2
+ *= require twitter-bootstrap-static/bootstrap
3
+ */
4
+
5
+ /* Override Bootstrap 3 font locations */
6
+ @font-face {
7
+ font-family: 'Glyphicons Halflings';
8
+ src: url('../assets/glyphicons-halflings-regular.eot');
9
+ src: url('../assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
10
+ url('../assets/glyphicons-halflings-regular.woff') format('woff'),
11
+ url('../assets/glyphicons-halflings-regular.ttf') format('truetype'),
12
+ url('../assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
13
+ }
@@ -0,0 +1,6 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_tree .
6
+ */
@@ -0,0 +1,29 @@
1
+ module KPM
2
+ class EngineController < ApplicationController
3
+
4
+ layout :get_layout
5
+
6
+ def get_layout
7
+ layout ||= KPM.config[:layout]
8
+ end
9
+
10
+ def current_tenant_user
11
+ # If the rails application on which that engine is mounted defines such method (Devise), we extract the current user,
12
+ # if not we default to nil, and serve our static mock configuration
13
+ user = current_user if respond_to?(:current_user)
14
+ KPM.current_tenant_user.call(session, user)
15
+ end
16
+
17
+ def options_for_klient
18
+ user = current_tenant_user
19
+ {
20
+ :username => user[:username],
21
+ :password => user[:password],
22
+ :session_id => user[:session_id],
23
+ :api_key => user[:api_key],
24
+ :api_secret => user[:api_secret]
25
+ }
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,109 @@
1
+ require 'kpm/client'
2
+
3
+ module KPM
4
+ class NodesInfoController < EngineController
5
+
6
+ def index
7
+ @nodes_info = ::KillBillClient::Model::NodesInfo.nodes_info(options_for_klient)
8
+
9
+ # For convenience, put pure OSGI bundles at the bottom
10
+ @nodes_info.each do |node_info|
11
+ next if node_info.plugins_info.nil?
12
+ node_info.plugins_info.sort! do |a, b|
13
+ if osgi_bundle?(a) && !osgi_bundle?(b)
14
+ 1
15
+ elsif !osgi_bundle?(a) && osgi_bundle?(b)
16
+ -1
17
+ else
18
+ a.plugin_name <=> b.plugin_name
19
+ end
20
+ end
21
+ end
22
+
23
+ @logs = ::Killbill::KPM::KPMClient.get_osgi_logs(options_for_klient).reverse
24
+
25
+ respond_to do |format|
26
+ format.html
27
+ format.js
28
+ end
29
+ end
30
+
31
+ def install_plugin
32
+ command_properties = [
33
+ build_node_command_property('forceDownload', params[:force_download] == '1')
34
+ ]
35
+ trigger_node_plugin_command('INSTALL_PLUGIN', command_properties)
36
+
37
+ redirect_to :action => :index
38
+ end
39
+
40
+ def install_plugin_from_fs
41
+ ::Killbill::KPM::KPMClient.install_plugin(params.require(:key),
42
+ params.require(:version),
43
+ params.require(:type),
44
+ params.require(:plugin).original_filename,
45
+ params.require(:plugin).read,
46
+ options_for_klient)
47
+
48
+ redirect_to :action => :index
49
+ end
50
+
51
+ def uninstall_plugin
52
+ trigger_node_plugin_command('UNINSTALL_PLUGIN')
53
+ head :ok
54
+ end
55
+
56
+ def start_plugin
57
+ trigger_node_plugin_command('START_PLUGIN')
58
+ head :ok
59
+ end
60
+
61
+ def stop_plugin
62
+ trigger_node_plugin_command('STOP_PLUGIN')
63
+ head :ok
64
+ end
65
+
66
+ def restart_plugin
67
+ trigger_node_plugin_command('RESTART_PLUGIN')
68
+ head :ok
69
+ end
70
+
71
+ private
72
+
73
+ def trigger_node_plugin_command(command_type, command_properties=[])
74
+ command_properties << build_node_command_property('pluginKey', params[:plugin_key])
75
+ command_properties << build_node_command_property('pluginName', params[:plugin_name])
76
+ command_properties << build_node_command_property('pluginVersion', params[:plugin_version])
77
+
78
+ trigger_node_command(command_type, command_properties)
79
+ end
80
+
81
+ def trigger_node_command(command_type, command_properties=[])
82
+ node_command = ::KillBillClient::Model::NodeCommandAttributes.new
83
+ node_command.system_command_type = true
84
+ node_command.node_command_type = command_type
85
+ node_command.node_command_properties = command_properties
86
+
87
+ # TODO Can we actually use node_name?
88
+ local_node_only = false
89
+
90
+ ::KillBillClient::Model::NodesInfo.trigger_node_command(node_command,
91
+ local_node_only,
92
+ options_for_klient[:username],
93
+ params[:reason],
94
+ params[:comment],
95
+ options_for_klient)
96
+ end
97
+
98
+ def build_node_command_property(key, value)
99
+ property = ::KillBillClient::Model::NodeCommandPropertyAttributes.new
100
+ property.key = key
101
+ property.value = value
102
+ property
103
+ end
104
+
105
+ def osgi_bundle?(plugin_info)
106
+ plugin_info.version.blank? || plugin_info.plugin_name.starts_with?('org.apache.felix.') || plugin_info.plugin_name.starts_with?('org.kill-bill.billing.killbill-platform-')
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,19 @@
1
+ require 'kpm/client'
2
+
3
+ module KPM
4
+ class PluginsController < EngineController
5
+
6
+ def index
7
+ begin
8
+ plugins = ::Killbill::KPM::KPMClient.get_available_plugins(true, options_for_klient)
9
+ rescue => e
10
+ # No connectivity, GitHub down, ...
11
+ Rails.logger.warn("Unable to get latest plugins, trying built-in directory: #{e.inspect}")
12
+ plugins = ::Killbill::KPM::KPMClient.get_available_plugins(false, options_for_klient)
13
+ end
14
+
15
+ @plugins = Hash[plugins.sort]
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ module KPM
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,31 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>KPM</title>
5
+ <%= yield :scripts %>
6
+ <%= stylesheet_link_tag 'application', :media => 'all' %>
7
+ <%= javascript_include_tag 'application' %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+ <div class="container-fluid">
11
+ <%- # :alert used by devise -%>
12
+ <% [:error, :alert].each do |key| %>
13
+ <% if flash[key] %>
14
+ <div class="row">
15
+ <div class="col-md-10 col-md-offset-2">
16
+ <div class="alert alert-error"><%= flash[key] %></div>
17
+ </div>
18
+ </div>
19
+ <% end %>
20
+ <% end %>
21
+ <% if flash[:notice] %>
22
+ <div class="row">
23
+ <div class="col-md-10 col-md-offset-2">
24
+ <div class="alert alert-info"><%= flash[:notice] %></div>
25
+ </div>
26
+ </div>
27
+ <% end %>
28
+ <%= yield %>
29
+ </div>
30
+ </body>
31
+ </html>
@@ -0,0 +1,43 @@
1
+ <table id="logs-table" class="table table-condensed table-striped mobile-data">
2
+ <thead>
3
+ <tr>
4
+ <th>Time</th>
5
+ <th>Name</th>
6
+ <th>Level</th>
7
+ <th>Message</th>
8
+ </tr>
9
+ </thead>
10
+ <tbody>
11
+ <% logs.each do |log| %>
12
+ <tr>
13
+ <td>
14
+ <% unless log['time'].blank? %>
15
+ <%= DateTime.strptime(log['time'].to_s, '%Q').strftime('%Y-%m-%d %H:%M:%S') %>
16
+ <% end %>
17
+ </td>
18
+ <td><%= log['name'] %></td>
19
+ <td>
20
+ <% if log['level'] == 'ERROR' %>
21
+ <span class="label label-danger"><%= log['level'] %></span>
22
+ <% elsif log['level'] == 'WARNING' %>
23
+ <span class="label label-warning"><%= log['level'] %></span>
24
+ <% else %>
25
+ <span class="label label-success"><%= log['level'] %></span>
26
+ <% end %>
27
+ </td>
28
+ <td><pre><%= log['message'] %></pre></td>
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
33
+
34
+ <%= javascript_tag do %>
35
+ $(document).ready(function() {
36
+ $('#logs-table').dataTable({
37
+ "dom": "<'row'r>t<'row'<'col-md-6'i><'col-md-6'p>>",
38
+ "pagingType": "full_numbers",
39
+ "pageLength": 50,
40
+ "ordering": false
41
+ });
42
+ });
43
+ <% end %>
@@ -0,0 +1,68 @@
1
+ <table id="nodes-table" class="table table-condensed table-striped mobile-data">
2
+ <thead>
3
+ <tr>
4
+ <th>Node name</th>
5
+ <th>Boot time</th>
6
+ <th>Updated date</th>
7
+ <th>Kill Bill version</th>
8
+ <th>Dependencies</th>
9
+ <th>Plugins</th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <% nodes_info.each do |node_info| %>
14
+ <tr>
15
+ <td><%= node_info.node_name %></td>
16
+ <td>
17
+ <% unless node_info.boot_time.blank? %>
18
+ <%= time_ago_in_words(DateTime.parse(node_info.boot_time)) %> ago
19
+ <% end %>
20
+ </td>
21
+ <td>
22
+ <% unless node_info.last_updated_date.blank? %>
23
+ <%= time_ago_in_words(DateTime.parse(node_info.last_updated_date)) %> ago
24
+ <% end %>
25
+ </td>
26
+ <td><%= node_info.kb_version %></td>
27
+ <td>
28
+ <ul>
29
+ <li>API: <%= node_info.api_version %></li>
30
+ <li>Plugin API: <%= node_info.plugin_api_version %></li>
31
+ <li>Platform: <%= node_info.platform_version %></li>
32
+ <li>Commons: <%= node_info.common_version %></li>
33
+ </ul>
34
+ </td>
35
+ <td>
36
+ <% unless (node_info.plugins_info || []).empty? %>
37
+ <ul>
38
+ <% node_info.plugins_info.each do |plugin_info| %>
39
+ <li>
40
+ <%= plugin_info.plugin_name %> <%= plugin_info.version %> <span class="label label-<%= plugin_info.state == 'RUNNING' ? 'success' : (plugin_info.state == 'INSTALLED' ? 'warning' : 'danger') %>"><%= plugin_info.state %></span>
41
+ <% if plugin_info.state == 'RUNNING' %>
42
+ <%= link_to '<i class="fa fa-pause"></i>'.html_safe, plugin_stop_path(:plugin_key => plugin_info.plugin_key, :plugin_name => plugin_info.plugin_name, :plugin_version => plugin_info.version), :method => :post, :title => 'Stop', :remote => true, :class => 'plugin-link' %>
43
+ <%= link_to '<i class="fa fa-refresh"></i>'.html_safe, plugin_restart_path(:plugin_key => plugin_info.plugin_key, :plugin_name => plugin_info.plugin_name, :plugin_version => plugin_info.version), :method => :post, :title => 'Restart', :remote => true, :class => 'plugin-link' %>
44
+ <% elsif plugin_info.state == 'INSTALLED' || plugin_info.state == 'STOPPED' %>
45
+ <%= link_to '<i class="fa fa-play"></i>'.html_safe, plugin_start_path(:plugin_key => plugin_info.plugin_key, :plugin_name => plugin_info.plugin_name, :plugin_version => plugin_info.version), :method => :post, :title => 'Start', :remote => true, :class => 'plugin-link' %>
46
+ <% end %>
47
+ <% unless plugin_info.version.nil? %>
48
+ <%= link_to '<i class="fa fa-eject"></i>'.html_safe, plugin_uninstall_path(:plugin_key => plugin_info.plugin_key, :plugin_name => plugin_info.plugin_name, :plugin_version => plugin_info.version), :method => :post, :title => 'Uninstall', :remote => true, :class => 'plugin-link' %>
49
+ <% end %>
50
+ </li>
51
+ <% end %>
52
+ </ul>
53
+ <% end %>
54
+ </td>
55
+ </tr>
56
+ <% end %>
57
+ </tbody>
58
+ </table>
59
+
60
+ <%= javascript_tag do %>
61
+ $(document).ready(function() {
62
+ $('#nodes-table').dataTable({
63
+ "dom": "t",
64
+ "paging": false,
65
+ "ordering": false
66
+ });
67
+ });
68
+ <% end %>