kpm 0.7.2 → 0.8.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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +66 -0
  3. data/Gemfile +2 -0
  4. data/README.adoc +111 -109
  5. data/Rakefile +2 -1
  6. data/bin/kpm +4 -2
  7. data/kpm.gemspec +8 -6
  8. data/lib/kpm.rb +3 -0
  9. data/lib/kpm/account.rb +267 -338
  10. data/lib/kpm/base_artifact.rb +33 -39
  11. data/lib/kpm/base_installer.rb +69 -83
  12. data/lib/kpm/blob.rb +29 -0
  13. data/lib/kpm/cli.rb +3 -1
  14. data/lib/kpm/coordinates.rb +6 -9
  15. data/lib/kpm/database.rb +90 -114
  16. data/lib/kpm/diagnostic_file.rb +126 -147
  17. data/lib/kpm/formatter.rb +74 -46
  18. data/lib/kpm/inspector.rb +22 -32
  19. data/lib/kpm/installer.rb +53 -46
  20. data/lib/kpm/kaui_artifact.rb +4 -3
  21. data/lib/kpm/killbill_plugin_artifact.rb +10 -7
  22. data/lib/kpm/killbill_server_artifact.rb +13 -12
  23. data/lib/kpm/migrations.rb +8 -7
  24. data/lib/kpm/nexus_helper/actions.rb +47 -8
  25. data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +87 -94
  26. data/lib/kpm/nexus_helper/nexus_facade.rb +5 -3
  27. data/lib/kpm/plugins_directory.rb +9 -8
  28. data/lib/kpm/plugins_directory.yml +8 -175
  29. data/lib/kpm/plugins_manager.rb +29 -24
  30. data/lib/kpm/sha1_checker.rb +31 -18
  31. data/lib/kpm/system.rb +105 -136
  32. data/lib/kpm/system_helpers/cpu_information.rb +56 -55
  33. data/lib/kpm/system_helpers/disk_space_information.rb +60 -63
  34. data/lib/kpm/system_helpers/entropy_available.rb +37 -39
  35. data/lib/kpm/system_helpers/memory_information.rb +52 -51
  36. data/lib/kpm/system_helpers/os_information.rb +45 -47
  37. data/lib/kpm/system_helpers/system_proxy.rb +10 -10
  38. data/lib/kpm/tasks.rb +364 -437
  39. data/lib/kpm/tenant_config.rb +68 -83
  40. data/lib/kpm/tomcat_manager.rb +9 -8
  41. data/lib/kpm/trace_logger.rb +18 -16
  42. data/lib/kpm/uninstaller.rb +81 -14
  43. data/lib/kpm/utils.rb +13 -14
  44. data/lib/kpm/version.rb +3 -1
  45. data/packaging/Gemfile +2 -0
  46. data/pom.xml +1 -1
  47. data/spec/kpm/remote/base_artifact_spec.rb +13 -15
  48. data/spec/kpm/remote/base_installer_spec.rb +30 -29
  49. data/spec/kpm/remote/installer_spec.rb +73 -73
  50. data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
  51. data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +19 -24
  52. data/spec/kpm/remote/killbill_server_artifact_spec.rb +17 -16
  53. data/spec/kpm/remote/migrations_spec.rb +12 -11
  54. data/spec/kpm/remote/nexus_facade_spec.rb +30 -26
  55. data/spec/kpm/remote/tenant_config_spec.rb +27 -26
  56. data/spec/kpm/remote/tomcat_manager_spec.rb +2 -1
  57. data/spec/kpm/unit/actions_spec.rb +52 -0
  58. data/spec/kpm/unit/base_artifact_spec.rb +17 -16
  59. data/spec/kpm/unit/cpu_information_spec.rb +67 -0
  60. data/spec/kpm/unit/disk_space_information_spec.rb +47 -0
  61. data/spec/kpm/unit/entropy_information_spec.rb +36 -0
  62. data/spec/kpm/unit/formatter_spec.rb +163 -0
  63. data/spec/kpm/unit/inspector_spec.rb +34 -42
  64. data/spec/kpm/unit/installer_spec.rb +5 -4
  65. data/spec/kpm/unit/memory_information_spec.rb +102 -0
  66. data/spec/kpm/unit/os_information_spec.rb +38 -0
  67. data/spec/kpm/unit/plugins_directory_spec.rb +34 -18
  68. data/spec/kpm/unit/plugins_manager_spec.rb +61 -65
  69. data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
  70. data/spec/kpm/unit/uninstaller_spec.rb +107 -61
  71. data/spec/kpm/unit_mysql/account_spec.rb +120 -135
  72. data/spec/spec_helper.rb +19 -17
  73. data/tasks/package.rake +18 -18
  74. metadata +17 -8
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KPM
4
+ class Blob
5
+ def initialize(value, tmp_dir)
6
+ @tmp_dir = tmp_dir
7
+ @blob_file = @tmp_dir + File::SEPARATOR + rand.to_s
8
+ store_value(value)
9
+ end
10
+
11
+ # On Macos systems, this will require defining a `secure_file_priv` config:
12
+ #
13
+ # e.g /usr/local/etc/my.cnf :
14
+ # [mysqld]
15
+ # ...
16
+ # secure_file_priv=""
17
+ def value
18
+ "LOAD_FILE(\"#{@blob_file}\")"
19
+ end
20
+
21
+ private
22
+
23
+ def store_value(value)
24
+ File.open(@blob_file, 'wb') do |file|
25
+ file.write(value)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
 
3
5
  module KPM
4
6
  class Cli < Thor
5
7
  include KPM::Tasks
6
8
  end
7
- end
9
+ end
@@ -1,9 +1,8 @@
1
- module KPM
1
+ # frozen_string_literal: true
2
2
 
3
+ module KPM
3
4
  class Coordinates
4
-
5
5
  class << self
6
-
7
6
  def build_coordinates(coordinate_map)
8
7
  group_id = coordinate_map[:group_id]
9
8
  artifact_id = coordinate_map[:artifact_id]
@@ -26,15 +25,13 @@ module KPM
26
25
  parts = entry.split(':')
27
26
  length = parts.size
28
27
  if length == 3
29
- {:group_id => parts[0], :artifact_id => parts[1], :packaging => parts[2]}
28
+ { group_id: parts[0], artifact_id: parts[1], packaging: parts[2] }
30
29
  elsif length == 4
31
- {:group_id => parts[0], :artifact_id => parts[1], :packaging => parts[2], :version => parts[3]}
30
+ { group_id: parts[0], artifact_id: parts[1], packaging: parts[2], version: parts[3] }
32
31
  elsif length == 5
33
- {:group_id => parts[0], :artifact_id => parts[1], :packaging => parts[2], :classifier => parts[3], :version => parts[4]}
32
+ { group_id: parts[0], artifact_id: parts[1], packaging: parts[2], classifier: parts[3], version: parts[4] }
34
33
  end
35
34
  end
36
-
37
35
  end
38
-
39
36
  end
40
- end
37
+ end
@@ -1,140 +1,116 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tmpdir'
2
4
 
3
5
  module KPM
4
-
5
6
  class Database
6
- class << self
7
-
8
- # Mysql Information functions
9
- LAST_INSERTED_ID = 'SELECT LAST_INSERT_ID();'
10
- ROWS_UPDATED = 'SELECT ROW_COUNT();'
11
-
12
- # Destination database
13
- DATABASE = ENV['DATABASE'] || 'killbill'
14
- USERNAME = ENV['USERNAME'] || 'root'
15
- PASSWORD = ENV['PASSWORD'] || 'root'
16
- HOST = ENV['HOST'] || 'localhost'
17
- PORT = ENV['PORT'] || '3306'
18
-
19
- COLUMN_NAME_POS = 3
20
-
21
- STATEMENT_TMP_FILE = Dir.mktmpdir('statement') + File::SEPARATOR + 'statement.sql'
22
-
23
- MYSQL_COMMAND_LINE = "mysql #{DATABASE} --user=#{USERNAME} --password=#{PASSWORD} "
24
-
25
- @@mysql_command_line = MYSQL_COMMAND_LINE
26
- @@username = USERNAME
27
- @@password = PASSWORD
28
- @@database = DATABASE
29
- @@host = HOST
30
- @@port = PORT
31
-
32
- def set_logger(logger)
33
- @@logger = logger
34
- end
35
-
36
- def set_credentials(user = nil, password = nil)
37
- @@username = user
38
- @@password = password
39
- end
7
+ # Mysql Information functions
8
+ LAST_INSERTED_ID = 'SELECT LAST_INSERT_ID();'
9
+ ROWS_UPDATED = 'SELECT ROW_COUNT();'
10
+
11
+ # Destination database
12
+ DATABASE = ENV['DATABASE'] || 'killbill'
13
+ USERNAME = ENV['USERNAME'] || 'root'
14
+ PASSWORD = ENV['PASSWORD'] || 'root'
15
+ HOST = ENV['HOST'] || 'localhost'
16
+ PORT = ENV['PORT'] || '3306'
17
+
18
+ COLUMN_NAME_POS = 3
19
+
20
+ STATEMENT_TMP_FILE = Dir.mktmpdir('statement') + File::SEPARATOR + 'statement.sql'
21
+
22
+ def initialize(database_name, host, port, username, password, logger)
23
+ @database_name = database_name || DATABASE
24
+ @host = host || HOST
25
+ @port = port || PORT
26
+ @username = username || USERNAME
27
+ @password = password || PASSWORD
28
+ @mysql_command_line = "mysql --max_allowed_packet=128M #{@database_name} --host=#{@host} --port=#{@port} --user=#{@username} --password=#{@password} "
29
+
30
+ @logger = logger
31
+ end
40
32
 
41
- def set_host(host)
42
- @@host = host
43
- end
33
+ def execute_insert_statement(table_name, query, qty_to_insert, _table_data, record_id = nil)
34
+ query = "set #{record_id[:variable]}=#{record_id[:value]}; #{query}" unless record_id.nil?
35
+ query = "SET sql_mode = ''; SET autocommit=0; #{query} COMMIT; SHOW WARNINGS;"
44
36
 
45
- def set_port(port)
46
- @@port = port
37
+ File.open(STATEMENT_TMP_FILE, 'w') do |s|
38
+ s.puts query
47
39
  end
48
40
 
49
- def set_database_name(database_name = nil)
50
- @@database = database_name
51
- end
41
+ response = `#{@mysql_command_line} < "#{STATEMENT_TMP_FILE}" 2>&1`
52
42
 
53
- def set_mysql_command_line
54
- @@mysql_command_line = "mysql #{@@database} --host=#{@@host} --port=#{@@port} --user=#{@@username} --password=#{@@password} "
43
+ if response.include? 'ERROR'
44
+ @logger.error "\e[91;1mTransaction that fails to be executed (first 1,000 chars)\e[0m"
45
+ # Queries can be really big (bulk imports)
46
+ @logger.error "\e[91m#{query[0..1000]}\e[0m"
47
+ raise Interrupt, "Importing table #{table_name}...... \e[91;1m#{response}\e[0m"
55
48
  end
56
49
 
57
- def execute_insert_statement(table_name, query, qty_to_insert, table_data, record_id = nil)
58
-
59
- unless record_id.nil?
60
- query = "set #{record_id[:variable]}=#{record_id[:value]}; #{query}"
61
- end
62
- query = "SET autocommit=0; #{query} COMMIT;"
63
-
64
- File.open(STATEMENT_TMP_FILE,'w') do |s|
65
- s.puts query
66
- end
67
-
68
- response = `#{@@mysql_command_line} < "#{STATEMENT_TMP_FILE}" 2>&1`
69
-
70
- if response.include? 'ERROR'
71
- @@logger.error "\e[91;1mTransaction that fails to be executed\e[0m"
72
- @@logger.error "\e[91m#{query}\e[0m"
73
- raise Interrupt, "Importing table #{table_name}...... \e[91;1m#{response}\e[0m"
74
- end
75
-
76
- if response.include? 'LAST_INSERT_ID'
77
- @@logger.info "\e[32mImporting table #{table_name}...... Row 1 of #{qty_to_insert} success\e[0m"
50
+ if response.include? 'LAST_INSERT_ID'
51
+ @logger.info "\e[32mImporting table #{table_name}...... Row 1 of #{qty_to_insert} success\e[0m"
78
52
 
79
- return response.split("\n")[1]
80
- end
81
-
82
- if response.include? 'ROW_COUNT'
83
- response_msg = response.split("\n")
84
- row_count_inserted = response_msg[response_msg.size - 1]
85
- @@logger.info "\e[32mImporting table #{table_name}...... Row #{ row_count_inserted || 1} of #{qty_to_insert} success\e[0m"
53
+ return response.split("\n")[1]
54
+ end
86
55
 
87
- return true
56
+ if response.include? 'ROW_COUNT'
57
+ # Typically, something like: "mysql: [Warning] Using a password on the command line interface can be insecure.\nROW_COUNT()\n3\n"
58
+ # With warning: "mysql: [Warning] Using a password on the command line interface can be insecure.\nROW_COUNT()\n1743\nLevel\tCode\tMessage\nWarning\t1264\tOut of range value for column 'amount' at row 582\n"
59
+ response_msg = response.split("\n")
60
+ idx_row_count_inserted = response_msg.index('ROW_COUNT()') + 1
61
+ row_count_inserted = response_msg[idx_row_count_inserted]
62
+ @logger.info "\e[32mImporting table #{table_name}...... Row #{row_count_inserted || 1} of #{qty_to_insert} success\e[0m"
63
+ if idx_row_count_inserted < response_msg.size - 1
64
+ warning_msg = response_msg[response_msg.size - 1]
65
+ @logger.warn "\e[91m#{warning_msg}\e[0m"
88
66
  end
89
-
90
- return true
91
67
  end
92
68
 
93
- def generate_insert_statement(tables)
94
-
95
- statements = []
96
- @@logger.info "\e[32mGenerating statements\e[0m"
97
-
98
- tables.each_key do |table_name|
99
- table = tables[table_name]
100
- if !table[:rows].nil? && table[:rows].size > 0
101
- columns_names = table[:col_names].join(",").gsub(/'/,'')
102
-
103
- rows = []
104
- table[:rows].each do |row|
105
- rows << row.map do |value|
106
- if value.is_a?(Symbol)
107
- value.to_s
108
- else
109
- escaped_value = value.to_s.gsub(/['"]/, "'" => "\\'", '"' => '\\"')
110
- .gsub('\N{LINE FEED}', "\n")
111
- .gsub('\N{VERTICAL LINE}', "|")
112
- "'#{escaped_value}'"
113
- end
114
- end.join(",")
115
- end
116
-
117
- value_data = rows.map{|row| "(#{row})" }.join(",")
118
-
119
- statements << {:query => get_insert_statement(table_name,columns_names,value_data, rows.size),
120
- :qty_to_insert => rows.size, :table_name => table_name, :table_data => table}
121
-
122
- end
69
+ true
70
+ end
123
71
 
72
+ def generate_insert_statement(tables)
73
+ statements = []
74
+ @logger.info "\e[32mGenerating statements\e[0m"
75
+
76
+ tables.each_key do |table_name|
77
+ table = tables[table_name]
78
+ next unless !table[:rows].nil? && !table[:rows].empty?
79
+
80
+ columns_names = table[:col_names].join(',').gsub(/'/, '')
81
+
82
+ rows = []
83
+ table[:rows].each do |row|
84
+ rows << row.map do |value|
85
+ if value.is_a?(Symbol)
86
+ value.to_s
87
+ elsif value.is_a?(Blob)
88
+ value.value
89
+ else
90
+ escaped_value = value.to_s.gsub(/['"]/, "'" => "\\'", '"' => '\\"')
91
+ .gsub('\N{LINE FEED}', "\n")
92
+ .gsub('\N{VERTICAL LINE}', '|')
93
+ "'#{escaped_value}'"
94
+ end
95
+ end.join(',')
124
96
  end
125
97
 
126
- statements
98
+ # Break the insert statement into small chunks to avoid timeouts
99
+ rows.each_slice(1000).each do |subset_of_rows|
100
+ value_data = subset_of_rows.map { |row| "(#{row})" }.join(',')
127
101
 
102
+ statements << { query: build_insert_statement(table_name, columns_names, value_data, subset_of_rows.size),
103
+ qty_to_insert: subset_of_rows.size, table_name: table_name, table_data: table }
104
+ end
128
105
  end
129
106
 
130
- private
107
+ statements
108
+ end
131
109
 
132
- def get_insert_statement(table_name, columns_names, values, rows_qty)
133
- return "INSERT INTO #{table_name} ( #{columns_names} ) VALUES #{values}; #{rows_qty == 1 ? LAST_INSERTED_ID : ROWS_UPDATED}"
134
- end
110
+ private
135
111
 
112
+ def build_insert_statement(table_name, columns_names, values, rows_qty)
113
+ "INSERT INTO #{table_name} ( #{columns_names} ) VALUES #{values}; #{rows_qty == 1 ? LAST_INSERTED_ID : ROWS_UPDATED}"
136
114
  end
137
-
138
115
  end
139
-
140
- end
116
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'tmpdir'
3
5
  require 'zip'
@@ -5,196 +7,173 @@ require 'json'
5
7
  require 'fileutils'
6
8
  require 'date'
7
9
 
8
-
9
10
  module KPM
11
+ class DiagnosticFile
12
+ # Temporary directory
13
+ TMP_DIR_PREFIX = 'killbill-diagnostics-'
14
+ TMP_DIR = Dir.mktmpdir(TMP_DIR_PREFIX)
15
+ TMP_LOGS_DIR = TMP_DIR + File::Separator + 'logs'
16
+
17
+ TENANT_FILE = 'tenant_config.data'
18
+ SYSTEM_FILE = 'system_configuration.data'
19
+ ACCOUNT_FILE = 'account.data'
20
+
21
+ TODAY_DATE = Date.today.strftime('%m-%d-%y')
22
+ ZIP_FILE = 'killbill-diagnostics-' + TODAY_DATE + '.zip'
23
+ ZIP_LOG_FILE = 'logs.zip'
24
+
25
+ def initialize(config_file = nil, killbill_api_credentials = nil, killbill_credentials = nil, killbill_url = nil,
26
+ database_name = nil, database_credentials = nil, database_host = nil, database_port = nil, kaui_web_path = nil,
27
+ killbill_web_path = nil, bundles_dir = nil, logger = nil)
28
+ @killbill_api_credentials = killbill_api_credentials
29
+ @killbill_credentials = killbill_credentials
30
+ @killbill_url = killbill_url
31
+ @database_name = database_name
32
+ @database_credentials = database_credentials
33
+ @database_host = database_host
34
+ @database_port = database_port
35
+ @config_file = config_file
36
+ @kaui_web_path = kaui_web_path
37
+ @killbill_web_path = killbill_web_path
38
+ @logger = logger
39
+ @original_logger_level = logger.level
40
+ @catalina_base = nil
41
+ @bundles_dir = bundles_dir
42
+ end
10
43
 
11
- class DiagnosticFile
12
-
13
- # Temporary directory
14
- TMP_DIR_PREFIX = 'killbill-diagnostics-'
15
- TMP_DIR = Dir.mktmpdir(TMP_DIR_PREFIX)
16
- TMP_LOGS_DIR = TMP_DIR + File::Separator + 'logs'
17
-
18
- TENANT_FILE = 'tenant_config.data'
19
- SYSTEM_FILE = 'system_configuration.data'
20
- ACCOUNT_FILE = 'account.data'
21
-
22
- TODAY_DATE = Date.today.strftime('%m-%d-%y')
23
- ZIP_FILE = 'killbill-diagnostics-' + TODAY_DATE + '.zip'
24
- ZIP_LOG_FILE = 'logs.zip'
25
-
26
- def initialize(config_file = nil, killbill_api_credentials = nil, killbill_credentials = nil, killbill_url = nil,
27
- database_name = nil, database_credentials = nil, database_host = nil, database_port = nil, kaui_web_path = nil,
28
- killbill_web_path = nil, bundles_dir = nil, logger = nil)
29
- @killbill_api_credentials = killbill_api_credentials
30
- @killbill_credentials = killbill_credentials
31
- @killbill_url = killbill_url
32
- @database_name = database_name
33
- @database_credentials = database_credentials
34
- @database_host = database_host
35
- @database_port = database_port
36
- @config_file = config_file
37
- @kaui_web_path = kaui_web_path;
38
- @killbill_web_path = killbill_web_path;
39
- @logger = logger
40
- @original_logger_level = logger.level;
41
- @catalina_base = nil
42
- @bundles_dir = bundles_dir
43
- end
44
-
45
- def export_data(account_id = nil, log_dir = nil)
46
- set_config(@config_file)
47
-
48
- tenant_export_file = get_tenant_config
49
- system_export_file = get_system_config
50
- account_export_file = get_account_data(account_id) unless account_id.nil?
51
- log_files = get_log_files(log_dir)
52
-
53
- if File.exist?(system_export_file) && File.exist?(tenant_export_file)
54
-
55
-
56
- zip_file_name = TMP_DIR + File::Separator + ZIP_FILE
57
-
58
- Zip::File.open(zip_file_name, Zip::File::CREATE) do |zipFile|
59
-
60
- zipFile.add(TENANT_FILE, tenant_export_file)
61
- zipFile.add(SYSTEM_FILE, system_export_file)
62
- zipFile.add(ACCOUNT_FILE, account_export_file) unless account_id.nil?
63
- zipFile.add(ZIP_LOG_FILE, log_files) unless log_files.nil?
44
+ def export_data(account_id = nil, log_dir = nil)
45
+ self.config = @config_file
64
46
 
65
- end
47
+ tenant_export_file = retrieve_tenant_config
48
+ system_export_file = retrieve_system_config
49
+ account_export_file = retrieve_account_data(account_id) unless account_id.nil?
50
+ log_files = retrieve_log_files(log_dir)
66
51
 
67
- @logger.info "\e[32mDiagnostic data exported under #{zip_file_name} \e[0m"
52
+ raise Interrupt, 'Account id or configuration file not found' unless File.exist?(system_export_file) && File.exist?(tenant_export_file)
68
53
 
69
- return zip_file_name
70
- else
71
- raise Interrupt, 'Account id or configuration file not found'
72
- end
54
+ zip_file_name = TMP_DIR + File::Separator + ZIP_FILE
73
55
 
56
+ Zip::File.open(zip_file_name, Zip::File::CREATE) do |zip_file|
57
+ zip_file.add(TENANT_FILE, tenant_export_file)
58
+ zip_file.add(SYSTEM_FILE, system_export_file)
59
+ zip_file.add(ACCOUNT_FILE, account_export_file) unless account_id.nil?
60
+ zip_file.add(ZIP_LOG_FILE, log_files) unless log_files.nil?
74
61
  end
75
62
 
76
- # Private methods
77
-
78
- private
63
+ @logger.info "\e[32mDiagnostic data exported under #{zip_file_name} \e[0m"
79
64
 
80
- def get_tenant_config
65
+ zip_file_name
66
+ end
81
67
 
82
- @logger.info 'Retrieving tenant configuration'
83
- # this suppress the message of where it put the account file, this is to avoid confusion
84
- @logger.level = Logger::WARN
68
+ # Private methods
85
69
 
86
- @killbill_api_credentials ||= [get_config('killbill', 'api_key'), get_config('killbill','api_secret')] unless @config_file.nil?
87
- @killbill_credentials ||= [get_config('killbill', 'user'), get_config('killbill','password')] unless @config_file.nil?
88
- @killbill_url ||= 'http://' + get_config('killbill', 'host').to_s + ':' + get_config('killbill','port').to_s unless @config_file.nil?
70
+ private
89
71
 
90
- tenant_config = KPM::TenantConfig.new(@killbill_api_credentials,
91
- @killbill_credentials, @killbill_url, @logger)
92
- export_file = tenant_config.export
72
+ def retrieve_tenant_config
73
+ @logger.info 'Retrieving tenant configuration'
74
+ # this suppress the message of where it put the account file, this is to avoid confusion
75
+ @logger.level = Logger::WARN
93
76
 
94
- final = TMP_DIR + File::Separator + TENANT_FILE
95
- FileUtils.move(export_file, final)
96
- @logger.level = @original_logger_level
77
+ @killbill_api_credentials ||= [retrieve_config('killbill', 'api_key'), retrieve_config('killbill', 'api_secret')] unless @config_file.nil?
78
+ @killbill_credentials ||= [retrieve_config('killbill', 'user'), retrieve_config('killbill', 'password')] unless @config_file.nil?
79
+ @killbill_url ||= 'http://' + retrieve_config('killbill', 'host').to_s + ':' + retrieve_config('killbill', 'port').to_s unless @config_file.nil?
97
80
 
98
- final
99
- end
81
+ tenant_config = KPM::TenantConfig.new(@killbill_api_credentials,
82
+ @killbill_credentials,
83
+ @killbill_url,
84
+ @logger)
85
+ export_file = tenant_config.export
100
86
 
101
- def get_system_config
87
+ final = TMP_DIR + File::Separator + TENANT_FILE
88
+ FileUtils.move(export_file, final)
89
+ @logger.level = @original_logger_level
102
90
 
103
- @logger.info 'Retrieving system configuration'
104
- system = KPM::System.new
105
- export_data = system.information(@bundles_dir, true, @config_file, @kaui_web_path, @killbill_web_path)
91
+ final
92
+ end
106
93
 
107
- get_system_catalina_base(export_data)
94
+ def retrieve_system_config
95
+ @logger.info 'Retrieving system configuration'
96
+ system = KPM::System.new(@logger)
97
+ export_data = system.information(@bundles_dir, true, @config_file, @kaui_web_path, @killbill_web_path)
108
98
 
109
- export_file = TMP_DIR + File::SEPARATOR + SYSTEM_FILE
110
- File.open(export_file, 'w') { |io| io.puts export_data }
111
- export_file
112
- end
99
+ system_catalina_base(export_data)
113
100
 
101
+ export_file = TMP_DIR + File::SEPARATOR + SYSTEM_FILE
102
+ File.open(export_file, 'w') { |io| io.puts export_data }
103
+ export_file
104
+ end
114
105
 
115
- def get_account_data(account_id)
106
+ def retrieve_account_data(account_id)
107
+ @logger.info 'Retrieving account data for id: ' + account_id
108
+ # this suppress the message of where it put the account file, this is to avoid confusion
109
+ @logger.level = Logger::WARN
116
110
 
117
- @logger.info 'Retrieving account data for id: ' + account_id
118
- # this suppress the message of where it put the account file, this is to avoid confusion
119
- @logger.level = Logger::WARN
111
+ account = KPM::Account.new(@config_file, @killbill_api_credentials, @killbill_credentials,
112
+ @killbill_url, @database_name,
113
+ @database_credentials, @database_host, @database_port, nil, @logger)
114
+ export_file = account.export_data(account_id)
120
115
 
121
- account = KPM::Account.new(@config_file, @killbill_api_credentials, @killbill_credentials,
122
- @killbill_url, @database_name,
123
- @database_credentials,@database_host, @database_port, nil, @logger)
124
- export_file = account.export_data(account_id)
116
+ final = TMP_DIR + File::Separator + ACCOUNT_FILE
117
+ FileUtils.move(export_file, final)
118
+ @logger.level = @original_logger_level
119
+ final
120
+ end
125
121
 
126
- final = TMP_DIR + File::Separator + ACCOUNT_FILE
127
- FileUtils.move(export_file, final)
128
- @logger.level = @original_logger_level
129
- final
122
+ def retrieve_log_files(log_dir)
123
+ if @catalina_base.nil? && log_dir.nil?
124
+ @logger.warn "\e[91;1mUnable to find Tomcat process, logs won't be collected: make sure to run kpm using the same user as the Tomcat process or pass the option --log-dir\e[0m"
125
+ return nil
130
126
  end
131
127
 
132
- def get_log_files(log_dir)
128
+ @logger.info 'Collecting log files'
129
+ log_base = log_dir || (@catalina_base + File::Separator + 'logs')
130
+ log_items = Dir.glob(log_base + File::Separator + '*')
133
131
 
134
- @logger.info 'Collecting log files'
132
+ zip_file_name = TMP_DIR + File::Separator + ZIP_LOG_FILE
135
133
 
136
- if @catalina_base.nil? && log_dir.nil?
137
- @logger.warn 'Unable to find Tomcat process, make sure to run kpm using the same user as the Tomcat process.'
138
- return nil
134
+ Zip::File.open(zip_file_name, Zip::File::CREATE) do |zip_file|
135
+ log_items.each do |file|
136
+ name = file.split('/').last
137
+ zip_file.add(name, file)
139
138
  end
140
-
141
- log_base = log_dir || (@catalina_base + File::Separator + 'logs')
142
- log_items = Dir.glob(log_base + File::Separator + '*')
143
-
144
- zip_file_name = TMP_DIR + File::Separator + ZIP_LOG_FILE
145
-
146
- Zip::File.open(zip_file_name, Zip::File::CREATE) do |zipFile|
147
-
148
- log_items.each do |file|
149
- name = file.split('/').last
150
- zipFile.add(name, file)
151
- end
152
-
153
- end
154
-
155
- zip_file_name
156
139
  end
157
140
 
158
- # Helpers
159
-
160
- def get_system_catalina_base(export_data)
161
- @catalina_base = nil
162
- system_json = JSON.parse(export_data)
141
+ zip_file_name
142
+ end
163
143
 
164
- return if system_json['java_system_information']['catalina.base'].nil?
144
+ # Helpers
165
145
 
166
- @catalina_base = system_json['java_system_information']['catalina.base']['value']
146
+ def system_catalina_base(export_data)
147
+ @catalina_base = nil
148
+ system_json = JSON.parse(export_data)
167
149
 
168
- end
150
+ return if system_json['java_system_information']['catalina.base'].nil?
169
151
 
170
- # Utils
152
+ @catalina_base = system_json['java_system_information']['catalina.base']['value']
153
+ end
171
154
 
172
- def get_config(parent, child)
173
- item = nil;
155
+ # Utils
174
156
 
175
- if not @config.nil?
157
+ def retrieve_config(parent, child)
158
+ item = nil
176
159
 
177
- config_parent = @config[parent]
160
+ unless @config.nil?
178
161
 
179
- if not config_parent.nil?
180
- item =config_parent[child]
181
- end
162
+ config_parent = @config[parent]
182
163
 
183
- end
164
+ item = config_parent[child] unless config_parent.nil?
184
165
 
185
- item
186
166
  end
187
167
 
188
- def set_config(config_file = nil)
189
- @config = nil
168
+ item
169
+ end
190
170
 
191
- if not config_file.nil?
192
- if not Dir[config_file][0].nil?
193
- @config = YAML::load_file(config_file)
194
- end
195
- end
171
+ def config=(config_file = nil)
172
+ @config = nil
196
173
 
197
- end
174
+ return if config_file.nil?
198
175
 
176
+ @config = YAML.load_file(config_file) unless Dir[config_file][0].nil?
199
177
  end
200
- end
178
+ end
179
+ end