kpm 0.7.0 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +73 -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 +268 -337
  10. data/lib/kpm/base_artifact.rb +40 -36
  11. data/lib/kpm/base_installer.rb +71 -84
  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 +92 -103
  16. data/lib/kpm/diagnostic_file.rb +126 -146
  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 +24 -10
  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 +14 -9
  28. data/lib/kpm/plugins_directory.yml +16 -175
  29. data/lib/kpm/plugins_manager.rb +29 -24
  30. data/lib/kpm/sha1_checker.rb +56 -15
  31. data/lib/kpm/system.rb +104 -135
  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 +370 -443
  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 +26 -12
  48. data/spec/kpm/remote/base_installer_spec.rb +30 -29
  49. data/spec/kpm/remote/installer_spec.rb +74 -72
  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 +30 -13
  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 +137 -136
  72. data/spec/spec_helper.rb +19 -17
  73. data/tasks/package.rake +18 -18
  74. metadata +19 -34
@@ -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,131 +1,120 @@
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
40
-
41
- def set_host(host)
42
- @@host = host
43
- end
44
-
45
- def set_port(port)
46
- @@port = port
47
- 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
48
32
 
49
- def set_database_name(database_name = nil)
50
- @@database = database_name
51
- 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;"
52
36
 
53
- def set_mysql_command_line
54
- @@mysql_command_line = "mysql #{@@database} --host=#{@@host} --port=#{@@port} --user=#{@@username} --password=#{@@password} "
37
+ File.open(STATEMENT_TMP_FILE, 'w') do |s|
38
+ s.puts query
55
39
  end
56
40
 
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
41
+ response = `#{@mysql_command_line} < "#{STATEMENT_TMP_FILE}" 2>&1`
67
42
 
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"
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
+ if response.include?('Table') && response.include?('doesn\'t exist')
48
+ @logger.warn "Skipping unknown table #{table_name}...."
49
+ else
73
50
  raise Interrupt, "Importing table #{table_name}...... \e[91;1m#{response}\e[0m"
74
51
  end
52
+ end
75
53
 
76
- if response.include? 'LAST_INSERT_ID'
77
- @@logger.info "\e[32mImporting table #{table_name}...... Row 1 of #{qty_to_insert} success\e[0m"
78
-
79
- return response.split("\n")[1]
80
- end
54
+ if response.include? 'LAST_INSERT_ID'
55
+ @logger.info "\e[32mImporting table #{table_name}...... Row 1 of #{qty_to_insert} success\e[0m"
81
56
 
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"
57
+ return response.split("\n")[1]
58
+ end
86
59
 
87
- return true
60
+ if response.include? 'ROW_COUNT'
61
+ # Typically, something like: "mysql: [Warning] Using a password on the command line interface can be insecure.\nROW_COUNT()\n3\n"
62
+ # 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"
63
+ response_msg = response.split("\n")
64
+ idx_row_count_inserted = response_msg.index('ROW_COUNT()') + 1
65
+ row_count_inserted = response_msg[idx_row_count_inserted]
66
+ @logger.info "\e[32mImporting table #{table_name}...... Row #{row_count_inserted || 1} of #{qty_to_insert} success\e[0m"
67
+ if idx_row_count_inserted < response_msg.size - 1
68
+ warning_msg = response_msg[response_msg.size - 1]
69
+ @logger.warn "\e[91m#{warning_msg}\e[0m"
88
70
  end
89
-
90
- return true
91
71
  end
92
72
 
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(/'/,'')
73
+ true
74
+ end
102
75
 
103
- rows = []
104
- table[:rows].each do |row|
105
- rows << row.map{|value| value.is_a?(Symbol) ? value.to_s : "'#{value.to_s.gsub(/['"]/, "'" => "\\'", '"' => '\\"')}'" }.join(",")
76
+ def generate_insert_statement(tables)
77
+ statements = []
78
+ @logger.info "\e[32mGenerating statements\e[0m"
79
+
80
+ tables.each_key do |table_name|
81
+ table = tables[table_name]
82
+ next unless !table[:rows].nil? && !table[:rows].empty?
83
+
84
+ columns_names = table[:col_names].join(',').gsub(/'/, '')
85
+
86
+ rows = []
87
+ table[:rows].each do |row|
88
+ rows << row.map do |value|
89
+ if value.is_a?(Symbol)
90
+ value.to_s
91
+ elsif value.is_a?(Blob)
92
+ value.value
93
+ else
94
+ escaped_value = value.to_s.gsub(/['"]/, "'" => "\\'", '"' => '\\"')
95
+ .gsub('\N{LINE FEED}', "\n")
96
+ .gsub('\N{VERTICAL LINE}', '|')
97
+ "'#{escaped_value}'"
106
98
  end
107
-
108
- value_data = rows.map{|row| "(#{row})" }.join(",")
109
-
110
- statements << {:query => get_insert_statement(table_name,columns_names,value_data, rows.size),
111
- :qty_to_insert => rows.size, :table_name => table_name, :table_data => table}
112
-
113
- end
114
-
99
+ end.join(',')
115
100
  end
116
101
 
117
- statements
102
+ # Break the insert statement into small chunks to avoid timeouts
103
+ rows.each_slice(1000).each do |subset_of_rows|
104
+ value_data = subset_of_rows.map { |row| "(#{row})" }.join(',')
118
105
 
106
+ statements << { query: build_insert_statement(table_name, columns_names, value_data, subset_of_rows.size),
107
+ qty_to_insert: subset_of_rows.size, table_name: table_name, table_data: table }
108
+ end
119
109
  end
120
110
 
121
- private
111
+ statements
112
+ end
122
113
 
123
- def get_insert_statement(table_name, columns_names, values, rows_qty)
124
- return "INSERT INTO #{table_name} ( #{columns_names} ) VALUES #{values}; #{rows_qty == 1 ? LAST_INSERTED_ID : ROWS_UPDATED}"
125
- end
114
+ private
126
115
 
116
+ def build_insert_statement(table_name, columns_names, values, rows_qty)
117
+ "INSERT INTO #{table_name} ( #{columns_names} ) VALUES #{values}; #{rows_qty == 1 ? LAST_INSERTED_ID : ROWS_UPDATED}"
127
118
  end
128
-
129
119
  end
130
-
131
- end
120
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'tmpdir'
3
5
  require 'zip'
@@ -5,195 +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
- else
70
- raise Interrupt, 'Account id or configuration file not found'
71
- end
54
+ zip_file_name = TMP_DIR + File::Separator + ZIP_FILE
72
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?
73
61
  end
74
62
 
75
- # Private methods
76
-
77
- private
63
+ @logger.info "\e[32mDiagnostic data exported under #{zip_file_name} \e[0m"
78
64
 
79
- def get_tenant_config
65
+ zip_file_name
66
+ end
80
67
 
81
- @logger.info 'Retrieving tenant configuration'
82
- # this suppress the message of where it put the account file, this is to avoid confusion
83
- @logger.level = Logger::WARN
68
+ # Private methods
84
69
 
85
- @killbill_api_credentials ||= [get_config('killbill', 'api_key'), get_config('killbill','api_secret')] unless @config_file.nil?
86
- @killbill_credentials ||= [get_config('killbill', 'user'), get_config('killbill','password')] unless @config_file.nil?
87
- @killbill_url ||= 'http://' + get_config('killbill', 'host').to_s + ':' + get_config('killbill','port').to_s unless @config_file.nil?
70
+ private
88
71
 
89
- tenant_config = KPM::TenantConfig.new(@killbill_api_credentials,
90
- @killbill_credentials, @killbill_url, @logger)
91
- 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
92
76
 
93
- final = TMP_DIR + File::Separator + TENANT_FILE
94
- FileUtils.move(export_file, final)
95
- @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?
96
80
 
97
- final
98
- end
81
+ tenant_config = KPM::TenantConfig.new(@killbill_api_credentials,
82
+ @killbill_credentials,
83
+ @killbill_url,
84
+ @logger)
85
+ export_file = tenant_config.export
99
86
 
100
- def get_system_config
87
+ final = TMP_DIR + File::Separator + TENANT_FILE
88
+ FileUtils.move(export_file, final)
89
+ @logger.level = @original_logger_level
101
90
 
102
- @logger.info 'Retrieving system configuration'
103
- system = KPM::System.new
104
- export_data = system.information(@bundles_dir, true, @config_file, @kaui_web_path, @killbill_web_path)
91
+ final
92
+ end
105
93
 
106
- 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)
107
98
 
108
- export_file = TMP_DIR + File::SEPARATOR + SYSTEM_FILE
109
- File.open(export_file, 'w') { |io| io.puts export_data }
110
- export_file
111
- end
99
+ system_catalina_base(export_data)
112
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
113
105
 
114
- 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
115
110
 
116
- @logger.info 'Retrieving account data for id: ' + account_id
117
- # this suppress the message of where it put the account file, this is to avoid confusion
118
- @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)
119
115
 
120
- account = KPM::Account.new(@config_file, @killbill_api_credentials, @killbill_credentials,
121
- @killbill_url, @database_name,
122
- @database_credentials,@database_host, @database_port, nil, @logger)
123
- 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
124
121
 
125
- final = TMP_DIR + File::Separator + ACCOUNT_FILE
126
- FileUtils.move(export_file, final)
127
- @logger.level = @original_logger_level
128
- 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
129
126
  end
130
127
 
131
- 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 + '*')
132
131
 
133
- @logger.info 'Collecting log files'
132
+ zip_file_name = TMP_DIR + File::Separator + ZIP_LOG_FILE
134
133
 
135
- if @catalina_base.nil? && log_dir.nil?
136
- @logger.warn 'Unable to find Tomcat process, make sure to run kpm using the same user as the Tomcat process.'
137
- 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)
138
138
  end
139
-
140
- log_base = log_dir || (@catalina_base + File::Separator + 'logs')
141
- log_items = Dir.glob(log_base + File::Separator + '*')
142
-
143
- zip_file_name = TMP_DIR + File::Separator + ZIP_LOG_FILE
144
-
145
- Zip::File.open(zip_file_name, Zip::File::CREATE) do |zipFile|
146
-
147
- log_items.each do |file|
148
- name = file.split('/').last
149
- zipFile.add(name, file)
150
- end
151
-
152
- end
153
-
154
- zip_file_name
155
139
  end
156
140
 
157
- # Helpers
158
-
159
- def get_system_catalina_base(export_data)
160
- @catalina_base = nil
161
- system_json = JSON.parse(export_data)
141
+ zip_file_name
142
+ end
162
143
 
163
- return if system_json['java_system_information']['catalina.base'].nil?
144
+ # Helpers
164
145
 
165
- @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)
166
149
 
167
- end
150
+ return if system_json['java_system_information']['catalina.base'].nil?
168
151
 
169
- # Utils
152
+ @catalina_base = system_json['java_system_information']['catalina.base']['value']
153
+ end
170
154
 
171
- def get_config(parent, child)
172
- item = nil;
155
+ # Utils
173
156
 
174
- if not @config.nil?
157
+ def retrieve_config(parent, child)
158
+ item = nil
175
159
 
176
- config_parent = @config[parent]
160
+ unless @config.nil?
177
161
 
178
- if not config_parent.nil?
179
- item =config_parent[child]
180
- end
162
+ config_parent = @config[parent]
181
163
 
182
- end
164
+ item = config_parent[child] unless config_parent.nil?
183
165
 
184
- item
185
166
  end
186
167
 
187
- def set_config(config_file = nil)
188
- @config = nil
168
+ item
169
+ end
189
170
 
190
- if not config_file.nil?
191
- if not Dir[config_file][0].nil?
192
- @config = YAML::load_file(config_file)
193
- end
194
- end
171
+ def config=(config_file = nil)
172
+ @config = nil
195
173
 
196
- end
174
+ return if config_file.nil?
197
175
 
176
+ @config = YAML.load_file(config_file) unless Dir[config_file][0].nil?
198
177
  end
199
- end
178
+ end
179
+ end