kpm 0.7.1 → 0.9.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.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +138 -0
- data/Gemfile +2 -0
- data/README.adoc +126 -109
- data/Rakefile +2 -1
- data/bin/kpm +4 -2
- data/kpm.gemspec +10 -8
- data/lib/kpm.rb +3 -0
- data/lib/kpm/account.rb +269 -337
- data/lib/kpm/base_artifact.rb +40 -36
- data/lib/kpm/base_installer.rb +71 -84
- data/lib/kpm/blob.rb +29 -0
- data/lib/kpm/cli.rb +3 -1
- data/lib/kpm/coordinates.rb +10 -12
- data/lib/kpm/database.rb +93 -103
- data/lib/kpm/diagnostic_file.rb +126 -146
- data/lib/kpm/formatter.rb +76 -48
- data/lib/kpm/inspector.rb +24 -34
- data/lib/kpm/installer.rb +53 -46
- data/lib/kpm/kaui_artifact.rb +4 -3
- data/lib/kpm/killbill_plugin_artifact.rb +10 -7
- data/lib/kpm/killbill_server_artifact.rb +24 -10
- data/lib/kpm/migrations.rb +26 -11
- data/lib/kpm/nexus_helper/actions.rb +45 -9
- data/lib/kpm/nexus_helper/github_api_calls.rb +70 -0
- data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +130 -108
- data/lib/kpm/nexus_helper/nexus_facade.rb +5 -3
- data/lib/kpm/plugins_directory.rb +14 -9
- data/lib/kpm/plugins_directory.yml +16 -175
- data/lib/kpm/plugins_manager.rb +29 -24
- data/lib/kpm/sha1_checker.rb +56 -15
- data/lib/kpm/system.rb +104 -135
- data/lib/kpm/system_helpers/cpu_information.rb +56 -55
- data/lib/kpm/system_helpers/disk_space_information.rb +60 -63
- data/lib/kpm/system_helpers/entropy_available.rb +37 -39
- data/lib/kpm/system_helpers/memory_information.rb +52 -51
- data/lib/kpm/system_helpers/os_information.rb +45 -47
- data/lib/kpm/system_helpers/system_proxy.rb +10 -10
- data/lib/kpm/tasks.rb +370 -443
- data/lib/kpm/tenant_config.rb +68 -83
- data/lib/kpm/tomcat_manager.rb +10 -8
- data/lib/kpm/trace_logger.rb +18 -16
- data/lib/kpm/uninstaller.rb +81 -14
- data/lib/kpm/utils.rb +13 -14
- data/lib/kpm/version.rb +3 -1
- data/packaging/Gemfile +2 -0
- data/pom.xml +1 -1
- data/spec/kpm/remote/base_artifact_spec.rb +33 -17
- data/spec/kpm/remote/base_installer_spec.rb +35 -34
- data/spec/kpm/remote/github_api_calls_spec.rb +40 -0
- data/spec/kpm/remote/installer_spec.rb +80 -78
- data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
- data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +25 -30
- data/spec/kpm/remote/killbill_server_artifact_spec.rb +30 -13
- data/spec/kpm/remote/migrations_spec.rb +12 -11
- data/spec/kpm/remote/nexus_facade_spec.rb +32 -28
- data/spec/kpm/remote/tenant_config_spec.rb +30 -29
- data/spec/kpm/remote/tomcat_manager_spec.rb +4 -3
- data/spec/kpm/unit/actions_spec.rb +52 -0
- data/spec/kpm/unit/base_artifact_spec.rb +19 -18
- data/spec/kpm/unit/cpu_information_spec.rb +67 -0
- data/spec/kpm/unit/disk_space_information_spec.rb +47 -0
- data/spec/kpm/unit/entropy_information_spec.rb +36 -0
- data/spec/kpm/unit/formatter_spec.rb +163 -0
- data/spec/kpm/unit/inspector_spec.rb +34 -42
- data/spec/kpm/unit/installer_spec.rb +7 -6
- data/spec/kpm/unit/memory_information_spec.rb +102 -0
- data/spec/kpm/unit/os_information_spec.rb +38 -0
- data/spec/kpm/unit/plugins_directory_spec.rb +38 -22
- data/spec/kpm/unit/plugins_manager_spec.rb +62 -66
- data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
- data/spec/kpm/unit/uninstaller_spec.rb +118 -72
- data/spec/kpm/unit_mysql/account_spec.rb +144 -143
- data/spec/spec_helper.rb +20 -18
- data/tasks/package.rake +18 -18
- metadata +26 -22
data/lib/kpm/blob.rb
ADDED
@@ -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
|
data/lib/kpm/cli.rb
CHANGED
data/lib/kpm/coordinates.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
|
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]
|
@@ -25,16 +24,15 @@ module KPM
|
|
25
24
|
def get_coordinate_map(entry)
|
26
25
|
parts = entry.split(':')
|
27
26
|
length = parts.size
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
case length
|
28
|
+
when 3
|
29
|
+
{ group_id: parts[0], artifact_id: parts[1], packaging: parts[2] }
|
30
|
+
when 4
|
31
|
+
{ group_id: parts[0], artifact_id: parts[1], packaging: parts[2], version: parts[3] }
|
32
|
+
when 5
|
33
|
+
{ group_id: parts[0], artifact_id: parts[1], packaging: parts[2], classifier: parts[3], version: parts[4] }
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
37
36
|
end
|
38
|
-
|
39
37
|
end
|
40
|
-
end
|
38
|
+
end
|
data/lib/kpm/database.rb
CHANGED
@@ -1,131 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tmpdir'
|
2
4
|
|
3
5
|
module KPM
|
4
|
-
|
5
6
|
class Database
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
37
|
+
File.open(STATEMENT_TMP_FILE, 'w') do |s|
|
38
|
+
s.puts query
|
55
39
|
end
|
56
40
|
|
57
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
77
|
-
|
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
|
-
|
83
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
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
|
+
case value
|
90
|
+
when Symbol
|
91
|
+
value.to_s
|
92
|
+
when Blob
|
93
|
+
value.value
|
94
|
+
else
|
95
|
+
escaped_value = value.to_s.gsub(/['"]/, "'" => "\\'", '"' => '\\"')
|
96
|
+
.gsub('\N{LINE FEED}', "\n")
|
97
|
+
.gsub('\N{VERTICAL LINE}', '|')
|
98
|
+
"'#{escaped_value}'"
|
106
99
|
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
|
-
|
100
|
+
end.join(',')
|
115
101
|
end
|
116
102
|
|
117
|
-
|
103
|
+
# Break the insert statement into small chunks to avoid timeouts
|
104
|
+
rows.each_slice(1000).each do |subset_of_rows|
|
105
|
+
value_data = subset_of_rows.map { |row| "(#{row})" }.join(',')
|
118
106
|
|
107
|
+
statements << { query: build_insert_statement(table_name, columns_names, value_data, subset_of_rows.size),
|
108
|
+
qty_to_insert: subset_of_rows.size, table_name: table_name, table_data: table }
|
109
|
+
end
|
119
110
|
end
|
120
111
|
|
121
|
-
|
112
|
+
statements
|
113
|
+
end
|
122
114
|
|
123
|
-
|
124
|
-
return "INSERT INTO #{table_name} ( #{columns_names} ) VALUES #{values}; #{rows_qty == 1 ? LAST_INSERTED_ID : ROWS_UPDATED}"
|
125
|
-
end
|
115
|
+
private
|
126
116
|
|
117
|
+
def build_insert_statement(table_name, columns_names, values, rows_qty)
|
118
|
+
"INSERT INTO #{table_name} ( #{columns_names} ) VALUES #{values}; #{rows_qty == 1 ? LAST_INSERTED_ID : ROWS_UPDATED}"
|
127
119
|
end
|
128
|
-
|
129
120
|
end
|
130
|
-
|
131
|
-
end
|
121
|
+
end
|
data/lib/kpm/diagnostic_file.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
52
|
+
raise Interrupt, 'Account id or configuration file not found' unless File.exist?(system_export_file) && File.exist?(tenant_export_file)
|
68
53
|
|
69
|
-
|
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
|
-
#
|
76
|
-
|
77
|
-
private
|
63
|
+
@logger.info "\e[32mDiagnostic data exported under #{zip_file_name} \e[0m"
|
78
64
|
|
79
|
-
|
65
|
+
zip_file_name
|
66
|
+
end
|
80
67
|
|
81
|
-
|
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
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
98
|
-
|
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
|
-
|
87
|
+
final = TMP_DIR + File::Separator + TENANT_FILE
|
88
|
+
FileUtils.move(export_file, final)
|
89
|
+
@logger.level = @original_logger_level
|
101
90
|
|
102
|
-
|
103
|
-
|
104
|
-
export_data = system.information(@bundles_dir, true, @config_file, @kaui_web_path, @killbill_web_path)
|
91
|
+
final
|
92
|
+
end
|
105
93
|
|
106
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
126
|
-
|
127
|
-
@logger.
|
128
|
-
|
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
|
-
|
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
|
-
|
132
|
+
zip_file_name = TMP_DIR + File::Separator + ZIP_LOG_FILE
|
134
133
|
|
135
|
-
|
136
|
-
|
137
|
-
|
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
|
-
|
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
|
-
|
144
|
+
# Helpers
|
164
145
|
|
165
|
-
|
146
|
+
def system_catalina_base(export_data)
|
147
|
+
@catalina_base = nil
|
148
|
+
system_json = JSON.parse(export_data)
|
166
149
|
|
167
|
-
|
150
|
+
return if system_json['java_system_information']['catalina.base'].nil?
|
168
151
|
|
169
|
-
|
152
|
+
@catalina_base = system_json['java_system_information']['catalina.base']['value']
|
153
|
+
end
|
170
154
|
|
171
|
-
|
172
|
-
item = nil;
|
155
|
+
# Utils
|
173
156
|
|
174
|
-
|
157
|
+
def retrieve_config(parent, child)
|
158
|
+
item = nil
|
175
159
|
|
176
|
-
|
160
|
+
unless @config.nil?
|
177
161
|
|
178
|
-
|
179
|
-
item =config_parent[child]
|
180
|
-
end
|
162
|
+
config_parent = @config[parent]
|
181
163
|
|
182
|
-
|
164
|
+
item = config_parent[child] unless config_parent.nil?
|
183
165
|
|
184
|
-
item
|
185
166
|
end
|
186
167
|
|
187
|
-
|
188
|
-
|
168
|
+
item
|
169
|
+
end
|
189
170
|
|
190
|
-
|
191
|
-
|
192
|
-
@config = YAML::load_file(config_file)
|
193
|
-
end
|
194
|
-
end
|
171
|
+
def config=(config_file = nil)
|
172
|
+
@config = nil
|
195
173
|
|
196
|
-
|
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
|