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.
Files changed (77) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +138 -0
  4. data/Gemfile +2 -0
  5. data/README.adoc +126 -109
  6. data/Rakefile +2 -1
  7. data/bin/kpm +4 -2
  8. data/kpm.gemspec +10 -8
  9. data/lib/kpm.rb +3 -0
  10. data/lib/kpm/account.rb +269 -337
  11. data/lib/kpm/base_artifact.rb +40 -36
  12. data/lib/kpm/base_installer.rb +71 -84
  13. data/lib/kpm/blob.rb +29 -0
  14. data/lib/kpm/cli.rb +3 -1
  15. data/lib/kpm/coordinates.rb +10 -12
  16. data/lib/kpm/database.rb +93 -103
  17. data/lib/kpm/diagnostic_file.rb +126 -146
  18. data/lib/kpm/formatter.rb +76 -48
  19. data/lib/kpm/inspector.rb +24 -34
  20. data/lib/kpm/installer.rb +53 -46
  21. data/lib/kpm/kaui_artifact.rb +4 -3
  22. data/lib/kpm/killbill_plugin_artifact.rb +10 -7
  23. data/lib/kpm/killbill_server_artifact.rb +24 -10
  24. data/lib/kpm/migrations.rb +26 -11
  25. data/lib/kpm/nexus_helper/actions.rb +45 -9
  26. data/lib/kpm/nexus_helper/github_api_calls.rb +70 -0
  27. data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +130 -108
  28. data/lib/kpm/nexus_helper/nexus_facade.rb +5 -3
  29. data/lib/kpm/plugins_directory.rb +14 -9
  30. data/lib/kpm/plugins_directory.yml +16 -175
  31. data/lib/kpm/plugins_manager.rb +29 -24
  32. data/lib/kpm/sha1_checker.rb +56 -15
  33. data/lib/kpm/system.rb +104 -135
  34. data/lib/kpm/system_helpers/cpu_information.rb +56 -55
  35. data/lib/kpm/system_helpers/disk_space_information.rb +60 -63
  36. data/lib/kpm/system_helpers/entropy_available.rb +37 -39
  37. data/lib/kpm/system_helpers/memory_information.rb +52 -51
  38. data/lib/kpm/system_helpers/os_information.rb +45 -47
  39. data/lib/kpm/system_helpers/system_proxy.rb +10 -10
  40. data/lib/kpm/tasks.rb +370 -443
  41. data/lib/kpm/tenant_config.rb +68 -83
  42. data/lib/kpm/tomcat_manager.rb +10 -8
  43. data/lib/kpm/trace_logger.rb +18 -16
  44. data/lib/kpm/uninstaller.rb +81 -14
  45. data/lib/kpm/utils.rb +13 -14
  46. data/lib/kpm/version.rb +3 -1
  47. data/packaging/Gemfile +2 -0
  48. data/pom.xml +1 -1
  49. data/spec/kpm/remote/base_artifact_spec.rb +33 -17
  50. data/spec/kpm/remote/base_installer_spec.rb +35 -34
  51. data/spec/kpm/remote/github_api_calls_spec.rb +40 -0
  52. data/spec/kpm/remote/installer_spec.rb +80 -78
  53. data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
  54. data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +25 -30
  55. data/spec/kpm/remote/killbill_server_artifact_spec.rb +30 -13
  56. data/spec/kpm/remote/migrations_spec.rb +12 -11
  57. data/spec/kpm/remote/nexus_facade_spec.rb +32 -28
  58. data/spec/kpm/remote/tenant_config_spec.rb +30 -29
  59. data/spec/kpm/remote/tomcat_manager_spec.rb +4 -3
  60. data/spec/kpm/unit/actions_spec.rb +52 -0
  61. data/spec/kpm/unit/base_artifact_spec.rb +19 -18
  62. data/spec/kpm/unit/cpu_information_spec.rb +67 -0
  63. data/spec/kpm/unit/disk_space_information_spec.rb +47 -0
  64. data/spec/kpm/unit/entropy_information_spec.rb +36 -0
  65. data/spec/kpm/unit/formatter_spec.rb +163 -0
  66. data/spec/kpm/unit/inspector_spec.rb +34 -42
  67. data/spec/kpm/unit/installer_spec.rb +7 -6
  68. data/spec/kpm/unit/memory_information_spec.rb +102 -0
  69. data/spec/kpm/unit/os_information_spec.rb +38 -0
  70. data/spec/kpm/unit/plugins_directory_spec.rb +38 -22
  71. data/spec/kpm/unit/plugins_manager_spec.rb +62 -66
  72. data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
  73. data/spec/kpm/unit/uninstaller_spec.rb +118 -72
  74. data/spec/kpm/unit_mysql/account_spec.rb +144 -143
  75. data/spec/spec_helper.rb +20 -18
  76. data/tasks/package.rake +18 -18
  77. metadata +26 -22
@@ -1,72 +1,73 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module KPM
2
4
  module SystemProxy
3
- module CpuInformation
4
- class << self
5
- def fetch
6
- cpu_info = nil
7
- if OS.windows?
8
- cpu_info = fetch_windows
9
- elsif OS.linux?
10
- cpu_info = fetch_linux
11
- elsif OS.mac?
12
- cpu_info = fetch_mac
13
- end
5
+ class CpuInformation
6
+ attr_reader :cpu_info, :labels
14
7
 
15
- cpu_info
16
- end
8
+ def initialize
9
+ @cpu_info = fetch
10
+ @labels = [{ label: :cpu_detail },
11
+ { label: :value }]
12
+ end
13
+
14
+ private
17
15
 
18
- def get_labels
19
- labels = [{:label => :cpu_detail},
20
- {:label => :value}]
21
- labels
16
+ def fetch
17
+ cpu_info = nil
18
+ if OS.windows?
19
+ cpu_info = fetch_windows
20
+ elsif OS.linux?
21
+ cpu_info = fetch_linux
22
+ elsif OS.mac?
23
+ cpu_info = fetch_mac
22
24
  end
23
25
 
24
- private
25
- def fetch_linux
26
- cpu_data = `cat /proc/cpuinfo 2>&1`.gsub("\t",'')
27
- cpu = get_hash(cpu_data)
28
- cpu
29
- end
26
+ cpu_info
27
+ end
30
28
 
31
- def fetch_mac
32
- cpu_data = `system_profiler SPHardwareDataType | grep -e "Processor" -e "Cores" -e "Cache" 2>&1`
33
- cpu = get_hash(cpu_data)
34
- cpu
35
- end
29
+ def fetch_linux
30
+ cpu_data = `cat /proc/cpuinfo 2>&1`.gsub("\t", '')
31
+ build_hash(cpu_data)
32
+ end
36
33
 
37
- def fetch_windows
38
- cpu_name = `wmic cpu get Name`.split("\n\n")
39
- cpu_caption = `wmic cpu get Caption`.split("\n\n")
40
- cpu_max_clock_speed = `wmic cpu get MaxClockSpeed`.split("\n\n")
41
- cpu_device_id = `wmic cpu get DeviceId`.split("\n\n")
42
- cpu_status = `wmic cpu get Status`.split("\n\n")
34
+ def fetch_mac
35
+ cpu_data = `system_profiler SPHardwareDataType | grep -e "Processor" -e "Cores" -e "Cache" 2>&1`
36
+ build_hash(cpu_data)
37
+ end
43
38
 
44
- cpu = Hash.new
45
- cpu[cpu_name[0].to_s.strip] = {:cpu_detail => cpu_name[0].to_s.strip, :value => cpu_name[1].to_s.strip}
46
- cpu[cpu_caption[0].to_s.strip] = {:cpu_detail => cpu_caption[0].to_s.strip, :value => cpu_caption[1].to_s.strip}
47
- cpu[cpu_max_clock_speed[0].to_s.strip] = {:cpu_detail => cpu_max_clock_speed[0].to_s.strip, :value => cpu_max_clock_speed[1].to_s.strip}
48
- cpu[cpu_device_id[0].to_s.strip] = {:cpu_detail => cpu_device_id[0].to_s.strip, :value => cpu_device_id[1].to_s.strip}
49
- cpu[cpu_status[0].to_s.strip] = {:cpu_detail => cpu_status[0].to_s.strip, :value => cpu_status[1].to_s.strip}
39
+ def fetch_windows
40
+ cpu_name = `wmic cpu get Name`.split("\n\n")
41
+ cpu_caption = `wmic cpu get Caption`.split("\n\n")
42
+ cpu_max_clock_speed = `wmic cpu get MaxClockSpeed`.split("\n\n")
43
+ cpu_device_id = `wmic cpu get DeviceId`.split("\n\n")
44
+ cpu_status = `wmic cpu get Status`.split("\n\n")
50
45
 
51
- cpu
52
- end
46
+ cpu = {}
47
+ cpu[cpu_name[0].to_s.strip] = { cpu_detail: cpu_name[0].to_s.strip, value: cpu_name[1].to_s.strip }
48
+ cpu[cpu_caption[0].to_s.strip] = { cpu_detail: cpu_caption[0].to_s.strip, value: cpu_caption[1].to_s.strip }
49
+ cpu[cpu_max_clock_speed[0].to_s.strip] = { cpu_detail: cpu_max_clock_speed[0].to_s.strip, value: cpu_max_clock_speed[1].to_s.strip }
50
+ cpu[cpu_device_id[0].to_s.strip] = { cpu_detail: cpu_device_id[0].to_s.strip, value: cpu_device_id[1].to_s.strip }
51
+ cpu[cpu_status[0].to_s.strip] = { cpu_detail: cpu_status[0].to_s.strip, value: cpu_status[1].to_s.strip }
53
52
 
54
- def get_hash(data)
55
- cpu = Hash.new
53
+ cpu
54
+ end
56
55
 
57
- unless data.nil?
58
- data.split("\n").each do |info|
59
- infos = info.split(':')
56
+ def build_hash(data)
57
+ cpu = {}
58
+ return cpu if data.nil?
60
59
 
61
- unless infos[0].to_s.strip.eql?('flags')
62
- cpu[infos[0].to_s.strip] = {:cpu_detail => infos[0].to_s.strip, :value => infos[1].to_s.strip}
63
- end
64
- end
65
- end
60
+ data.split("\n").each do |info|
61
+ infos = info.split(':')
66
62
 
67
- cpu
68
- end
63
+ key = infos[0].to_s.strip
64
+ next if key.empty? || key.eql?('flags')
65
+
66
+ cpu[key] = { cpu_detail: key, value: infos[1].to_s.strip }
69
67
  end
68
+
69
+ cpu
70
+ end
70
71
  end
71
72
  end
72
- end
73
+ end
@@ -1,84 +1,81 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module KPM
2
4
  module SystemProxy
3
- module DiskSpaceInformation
4
- class << self
5
-
6
- def fetch
7
- disk_space_info = nil
8
- if OS.windows?
9
- disk_space_info = fetch_windows
10
- elsif OS.linux?
11
- disk_space_info = fetch_linux_mac(5)
12
- elsif OS.mac?
13
- disk_space_info = fetch_linux_mac(8)
14
- end
5
+ class DiskSpaceInformation
6
+ attr_reader :disk_space_info, :labels
7
+
8
+ def initialize
9
+ data_keys = []
10
+ @disk_space_info = fetch(data_keys)
11
+ @labels = []
12
+ data_keys.each { |key| @labels.push(label: key.gsub(' ', '_').to_sym) }
13
+ end
15
14
 
16
- disk_space_info
17
- end
15
+ private
18
16
 
19
- def get_labels
20
- labels = []
21
- @@data_keys.each { |key| labels.push({:label => key.gsub(' ','_').to_sym})}
22
- labels
17
+ def fetch(data_keys)
18
+ disk_space_info = nil
19
+ if OS.windows?
20
+ disk_space_info = fetch_windows(data_keys)
21
+ elsif OS.linux?
22
+ disk_space_info = fetch_linux_mac(5, data_keys)
23
+ elsif OS.mac?
24
+ disk_space_info = fetch_linux_mac(8, data_keys)
23
25
  end
24
26
 
25
- private
26
- def fetch_linux_mac(cols_count)
27
- disk_space_info = `df 2>&1`
28
- disk_space = get_hash(disk_space_info,cols_count,true)
29
- disk_space
30
- end
27
+ disk_space_info
28
+ end
31
29
 
32
- def fetch_windows
33
- disk_space_info = `wmic logicaldisk get size,freespace,caption 2>&1`
34
- disk_space = get_hash(disk_space_info,3,false)
35
- disk_space
36
- end
30
+ def fetch_linux_mac(cols_count, data_keys)
31
+ disk_space_info = `df 2>&1`
32
+ build_hash(disk_space_info, cols_count, true, data_keys)
33
+ end
37
34
 
38
- def get_hash(data, cols_count, merge_last_two_columns)
39
- disk_space = Hash.new
35
+ def fetch_windows(data_keys)
36
+ disk_space_info = `wmic logicaldisk get size,freespace,caption 2>&1`
37
+ build_hash(disk_space_info, 3, false, data_keys)
38
+ end
40
39
 
41
- unless data.nil?
40
+ def build_hash(data, cols_count, merge_last_two_columns, data_keys)
41
+ disk_space = {}
42
42
 
43
- data_table = data.split("\n")
43
+ unless data.nil?
44
44
 
45
- @@data_keys = data_table[0].split(' ')
45
+ data_table = data.split("\n")
46
46
 
47
- if merge_last_two_columns
48
- @@data_keys[@@data_keys.length - 2] = @@data_keys[@@data_keys.length - 2] + ' ' + @@data_keys[@@data_keys.length - 1]
49
- @@data_keys.delete_at(@@data_keys.length - 1)
50
- end
47
+ data_keys.concat(data_table[0].split(' '))
51
48
 
52
- row_num = 0
53
- data_table.each do |row|
54
- cols = row.split(' ')
55
- row_num += 1
56
- unless cols[0].to_s.eql?(@@data_keys[0])
57
- key = 'DiskInfo_'+row_num.to_s
58
- disk_space[key] = Hash.new
59
- cols.each_index do |idx|
60
- if idx > cols_count
61
- break
62
- end
63
-
64
- value = cols[idx].to_s.strip
65
- if idx == cols_count && cols.length - 1 > idx
66
- for i in cols_count+1..cols.length
67
- value += ' ' + cols[i].to_s.strip
68
- end
69
- end
70
-
71
- disk_space[key][@@data_keys[idx].gsub(' ','_').to_sym] = value
72
- end
73
- end
49
+ if merge_last_two_columns
50
+ data_keys[data_keys.length - 2] = data_keys[data_keys.length - 2] + ' ' + data_keys[data_keys.length - 1]
51
+ data_keys.delete_at(data_keys.length - 1)
52
+ end
74
53
 
54
+ row_num = 0
55
+ data_table.each do |row|
56
+ cols = row.split(' ')
57
+ row_num += 1
58
+ next if cols[0].to_s.eql?(data_keys[0])
59
+
60
+ key = 'DiskInfo_' + row_num.to_s
61
+ disk_space[key] = {}
62
+ cols.each_index do |idx|
63
+ break if idx > cols_count
64
+
65
+ value = cols[idx].to_s.strip
66
+ if idx == cols_count && cols.length - 1 > idx
67
+ (cols_count + 1..cols.length).each do |i|
68
+ value += ' ' + cols[i].to_s.strip
69
+ end
75
70
  end
76
- end
77
71
 
78
- disk_space
72
+ disk_space[key][data_keys[idx].gsub(' ', '_').to_sym] = value
73
+ end
79
74
  end
75
+ end
80
76
 
77
+ disk_space
81
78
  end
82
79
  end
83
80
  end
84
- end
81
+ end
@@ -1,52 +1,50 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module KPM
2
4
  module SystemProxy
3
- module EntropyAvailable
4
- class << self
5
-
6
- def fetch
7
- entropy_available = nil
8
- if OS.windows?
9
- entropy_available = fetch_windows
10
- elsif OS.linux?
11
- entropy_available = fetch_linux
12
- elsif OS.mac?
13
- entropy_available = fetch_mac
14
- end
15
-
16
- entropy_available
17
- end
5
+ class EntropyAvailable
6
+ attr_reader :entropy_available, :labels
7
+
8
+ def initialize
9
+ @entropy_available = fetch
10
+ @labels = [{ label: :entropy },
11
+ { label: :value }]
12
+ end
13
+
14
+ private
18
15
 
19
- def get_labels
20
- labels = [{:label => :entropy},
21
- {:label => :value}]
22
- labels
16
+ def fetch
17
+ entropy_available = nil
18
+ if OS.windows?
19
+ entropy_available = fetch_windows
20
+ elsif OS.linux?
21
+ entropy_available = fetch_linux
22
+ elsif OS.mac?
23
+ entropy_available = fetch_mac
23
24
  end
24
25
 
25
- private
26
- def fetch_linux
27
- entropy_available_data = `cat /proc/sys/kernel/random/entropy_avail 2>&1`.gsub("\n",'')
28
- entropy_available = get_hash(entropy_available_data)
29
- entropy_available
30
- end
26
+ entropy_available
27
+ end
31
28
 
32
- def fetch_mac
33
- entropy_available = get_hash('-')
34
- entropy_available
35
- end
29
+ def fetch_linux
30
+ entropy_available_data = `cat /proc/sys/kernel/random/entropy_avail 2>&1`.gsub("\n", '')
31
+ build_hash(entropy_available_data)
32
+ end
36
33
 
37
- def fetch_windows
38
- entropy_available = get_hash('-')
39
- entropy_available
40
- end
34
+ def fetch_mac
35
+ build_hash('-')
36
+ end
41
37
 
42
- def get_hash(data)
43
- entropy_available = Hash.new
44
- entropy_available['entropy_available'] = {:entropy => 'available', :value => data}
38
+ def fetch_windows
39
+ build_hash('-')
40
+ end
45
41
 
46
- entropy_available
47
- end
42
+ def build_hash(data)
43
+ entropy_available = {}
44
+ entropy_available['entropy_available'] = { entropy: 'available', value: data }
48
45
 
46
+ entropy_available
49
47
  end
50
48
  end
51
49
  end
52
- end
50
+ end
@@ -1,71 +1,72 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module KPM
2
4
  module SystemProxy
3
- module MemoryInformation
4
- class << self
5
+ class MemoryInformation
6
+ attr_reader :memory_info, :labels
5
7
 
6
- def fetch
7
- memory_info = nil
8
- if OS.windows?
9
- memory_info = fetch_windows
10
- elsif OS.linux?
11
- memory_info = fetch_linux
12
- elsif OS.mac?
13
- memory_info = fetch_mac
14
- end
8
+ def initialize
9
+ @memory_info = fetch
10
+ @labels = [{ label: :memory_detail },
11
+ { label: :value }]
12
+ end
15
13
 
16
- memory_info
17
- end
14
+ private
18
15
 
19
- def get_labels
20
- labels = [{:label => :memory_detail},
21
- {:label => :value}]
22
- labels
16
+ def fetch
17
+ memory_info = nil
18
+ if OS.windows?
19
+ memory_info = fetch_windows
20
+ elsif OS.linux?
21
+ memory_info = fetch_linux
22
+ elsif OS.mac?
23
+ memory_info = fetch_mac
23
24
  end
24
25
 
25
- private
26
- def fetch_linux
27
- mem_data = `cat /proc/meminfo 2>&1`.gsub("\t",'')
28
- mem = get_hash(mem_data)
29
- mem
30
- end
26
+ memory_info
27
+ end
31
28
 
32
- def fetch_mac
33
- mem_data = `vm_stat 2>&1`.gsub(".",'')
34
- mem = get_hash(mem_data)
29
+ def fetch_linux
30
+ mem_data = `cat /proc/meminfo 2>&1`.gsub("\t", '')
31
+ build_hash(mem_data)
32
+ end
35
33
 
36
- mem.each_key do |key|
37
- mem[key][:value] = ((mem[key][:value].to_i * 4096) / 1024 / 1024).to_s + 'MB'
38
- mem[key][:memory_detail] = mem[key][:memory_detail].gsub('Pages','Memory')
39
- end
34
+ def fetch_mac
35
+ mem_data = `vm_stat 2>&1`.gsub('.', '')
36
+ mem_total_data = `system_profiler SPHardwareDataType | grep " Memory:" 2>&1`
37
+ build_hash_mac(mem_data, mem_total_data)
38
+ end
40
39
 
41
- mem_total_data = `system_profiler SPHardwareDataType | grep " Memory:" 2>&1`
42
- mem_total = get_hash(mem_total_data)
40
+ def build_hash_mac(mem_data, mem_total_data)
41
+ mem = build_hash(mem_data)
43
42
 
44
- mem = mem_total.merge(mem)
43
+ mem.each_key do |key|
44
+ mem[key][:value] = ((mem[key][:value].to_i * 4096) / 1024 / 1024).to_s + 'MB'
45
+ mem[key][:memory_detail] = mem[key][:memory_detail].gsub('Pages', 'Memory')
46
+ end
45
47
 
46
- mem
47
- end
48
+ mem_total = build_hash(mem_total_data)
48
49
 
49
- def fetch_windows
50
- mem_data = `systeminfo | findstr /C:"Total Physical Memory" /C:"Available Physical Memory"`
51
- mem = get_hash(mem_data)
52
- mem
53
- end
50
+ mem_total.merge(mem)
51
+ end
54
52
 
55
- def get_hash(data)
56
- mem = Hash.new
53
+ def fetch_windows
54
+ mem_data = `systeminfo | findstr /C:"Total Physical Memory" /C:"Available Physical Memory"`
55
+ build_hash(mem_data)
56
+ end
57
57
 
58
- unless data.nil?
59
- data.split("\n").each do |info|
60
- infos = info.split(':')
61
- mem[infos[0].to_s.strip] = {:memory_detail => infos[0].to_s.strip, :value => infos[1].to_s.strip}
62
- end
63
- end
58
+ def build_hash(data)
59
+ mem = {}
60
+ return mem if data.nil?
64
61
 
65
- mem
66
- end
62
+ data.split("\n").each do |info|
63
+ infos = info.split(':')
64
+ key = infos[0].to_s.strip.gsub('"', '')
65
+ mem[key] = { memory_detail: key, value: infos[1].to_s.strip }
66
+ end
67
67
 
68
+ mem
68
69
  end
69
70
  end
70
71
  end
71
- end
72
+ end