kpm 0.7.2 → 0.10.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 +2 -0
- data/.rubocop.yml +138 -0
- data/Gemfile +2 -0
- data/README.adoc +144 -107
- data/Rakefile +2 -1
- data/bin/kpm +4 -2
- data/kpm.gemspec +11 -8
- data/lib/kpm.rb +3 -0
- data/lib/kpm/account.rb +268 -338
- data/lib/kpm/base_artifact.rb +33 -39
- data/lib/kpm/base_installer.rb +69 -83
- 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 +94 -113
- data/lib/kpm/diagnostic_file.rb +126 -147
- 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 +13 -12
- data/lib/kpm/migrations.rb +26 -11
- data/lib/kpm/nexus_helper/actions.rb +52 -9
- data/lib/kpm/nexus_helper/cloudsmith_api_calls.rb +83 -0
- 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 +9 -8
- data/lib/kpm/plugins_directory.yml +14 -173
- data/lib/kpm/plugins_manager.rb +29 -24
- data/lib/kpm/sha1_checker.rb +31 -18
- 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 +381 -438
- 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 +211 -40
- data/spec/kpm/remote/base_artifact_spec.rb +20 -20
- data/spec/kpm/remote/base_installer_spec.rb +35 -34
- data/spec/kpm/remote/cloudsmith_api_calls_spec.rb +40 -0
- data/spec/kpm/remote/github_api_calls_spec.rb +40 -0
- data/spec/kpm/remote/installer_spec.rb +80 -79
- 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 +17 -16
- 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 +127 -142
- data/spec/spec_helper.rb +20 -18
- data/tasks/package.rake +18 -18
- metadata +42 -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,140 +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(/'/,'')
|
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
|
73
|
+
true
|
74
|
+
end
|
123
75
|
|
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}'"
|
99
|
+
end
|
100
|
+
end.join(',')
|
124
101
|
end
|
125
102
|
|
126
|
-
|
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(',')
|
127
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
|
128
110
|
end
|
129
111
|
|
130
|
-
|
112
|
+
statements
|
113
|
+
end
|
131
114
|
|
132
|
-
|
133
|
-
return "INSERT INTO #{table_name} ( #{columns_names} ) VALUES #{values}; #{rows_qty == 1 ? LAST_INSERTED_ID : ROWS_UPDATED}"
|
134
|
-
end
|
115
|
+
private
|
135
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}"
|
136
119
|
end
|
137
|
-
|
138
120
|
end
|
139
|
-
|
140
|
-
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,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
|
-
|
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
|
-
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
|
-
#
|
77
|
-
|
78
|
-
private
|
63
|
+
@logger.info "\e[32mDiagnostic data exported under #{zip_file_name} \e[0m"
|
79
64
|
|
80
|
-
|
65
|
+
zip_file_name
|
66
|
+
end
|
81
67
|
|
82
|
-
|
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
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
99
|
-
|
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
|
-
|
87
|
+
final = TMP_DIR + File::Separator + TENANT_FILE
|
88
|
+
FileUtils.move(export_file, final)
|
89
|
+
@logger.level = @original_logger_level
|
102
90
|
|
103
|
-
|
104
|
-
|
105
|
-
export_data = system.information(@bundles_dir, true, @config_file, @kaui_web_path, @killbill_web_path)
|
91
|
+
final
|
92
|
+
end
|
106
93
|
|
107
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
-
|
127
|
-
|
128
|
-
@logger.
|
129
|
-
|
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
|
-
|
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
|
-
|
132
|
+
zip_file_name = TMP_DIR + File::Separator + ZIP_LOG_FILE
|
135
133
|
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
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
|
-
|
144
|
+
# Helpers
|
165
145
|
|
166
|
-
|
146
|
+
def system_catalina_base(export_data)
|
147
|
+
@catalina_base = nil
|
148
|
+
system_json = JSON.parse(export_data)
|
167
149
|
|
168
|
-
|
150
|
+
return if system_json['java_system_information']['catalina.base'].nil?
|
169
151
|
|
170
|
-
|
152
|
+
@catalina_base = system_json['java_system_information']['catalina.base']['value']
|
153
|
+
end
|
171
154
|
|
172
|
-
|
173
|
-
item = nil;
|
155
|
+
# Utils
|
174
156
|
|
175
|
-
|
157
|
+
def retrieve_config(parent, child)
|
158
|
+
item = nil
|
176
159
|
|
177
|
-
|
160
|
+
unless @config.nil?
|
178
161
|
|
179
|
-
|
180
|
-
item =config_parent[child]
|
181
|
-
end
|
162
|
+
config_parent = @config[parent]
|
182
163
|
|
183
|
-
|
164
|
+
item = config_parent[child] unless config_parent.nil?
|
184
165
|
|
185
|
-
item
|
186
166
|
end
|
187
167
|
|
188
|
-
|
189
|
-
|
168
|
+
item
|
169
|
+
end
|
190
170
|
|
191
|
-
|
192
|
-
|
193
|
-
@config = YAML::load_file(config_file)
|
194
|
-
end
|
195
|
-
end
|
171
|
+
def config=(config_file = nil)
|
172
|
+
@config = nil
|
196
173
|
|
197
|
-
|
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
|