kpm 0.7.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +73 -0
- data/Gemfile +2 -0
- data/README.adoc +111 -109
- data/Rakefile +2 -1
- data/bin/kpm +4 -2
- data/kpm.gemspec +8 -6
- data/lib/kpm.rb +3 -0
- data/lib/kpm/account.rb +268 -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 +6 -9
- data/lib/kpm/database.rb +92 -103
- data/lib/kpm/diagnostic_file.rb +126 -146
- data/lib/kpm/formatter.rb +74 -46
- data/lib/kpm/inspector.rb +22 -32
- 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 +8 -7
- data/lib/kpm/nexus_helper/actions.rb +47 -8
- data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +87 -94
- 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 +9 -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 +26 -12
- data/spec/kpm/remote/base_installer_spec.rb +30 -29
- data/spec/kpm/remote/installer_spec.rb +74 -72
- data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
- data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +19 -24
- 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 +30 -26
- data/spec/kpm/remote/tenant_config_spec.rb +27 -26
- data/spec/kpm/remote/tomcat_manager_spec.rb +2 -1
- data/spec/kpm/unit/actions_spec.rb +52 -0
- data/spec/kpm/unit/base_artifact_spec.rb +17 -16
- 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 +5 -4
- 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 +34 -18
- data/spec/kpm/unit/plugins_manager_spec.rb +61 -65
- data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
- data/spec/kpm/unit/uninstaller_spec.rb +107 -61
- data/spec/kpm/unit_mysql/account_spec.rb +137 -136
- data/spec/spec_helper.rb +19 -17
- data/tasks/package.rake +18 -18
- metadata +19 -34
data/lib/kpm/base_artifact.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'digest/sha1'
|
2
4
|
require 'rexml/document'
|
3
5
|
|
4
6
|
module KPM
|
5
|
-
|
6
7
|
class ArtifactCorruptedException < IOError
|
7
8
|
def message
|
8
9
|
'Downloaded artifact failed checksum verification'
|
@@ -34,34 +35,34 @@ module KPM
|
|
34
35
|
KAUI_CLASSIFIER = nil
|
35
36
|
|
36
37
|
class << self
|
37
|
-
def pull(logger, group_id, artifact_id, packaging='jar', classifier=nil, version='LATEST', destination_path=nil, sha1_file=nil, force_download=false, verify_sha1=true, overrides={}, ssl_verify=true)
|
38
|
-
coordinate_map = {:
|
38
|
+
def pull(logger, group_id, artifact_id, packaging = 'jar', classifier = nil, version = 'LATEST', destination_path = nil, sha1_file = nil, force_download = false, verify_sha1 = true, overrides = {}, ssl_verify = true)
|
39
|
+
coordinate_map = { group_id: group_id, artifact_id: artifact_id, packaging: packaging, classifier: classifier, version: version }
|
39
40
|
pull_and_put_in_place(logger, coordinate_map, nil, destination_path, false, sha1_file, force_download, verify_sha1, overrides, ssl_verify)
|
40
41
|
end
|
41
42
|
|
42
|
-
def pull_from_fs(logger, file_path, destination_path=nil)
|
43
|
+
def pull_from_fs(logger, file_path, destination_path = nil)
|
43
44
|
pull_from_fs_and_put_in_place(logger, file_path, destination_path)
|
44
45
|
end
|
45
46
|
|
46
|
-
def nexus_remote(overrides={}, ssl_verify=true, logger=nil)
|
47
|
+
def nexus_remote(overrides = {}, ssl_verify = true, logger = nil)
|
47
48
|
# overrides typically comes from the kpm.yml where we expect keys as String
|
48
|
-
overrides_sym = (overrides || {}).each_with_object({}) {|(k,v), h| h[k.to_sym] = v}
|
49
|
+
overrides_sym = (overrides || {}).each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
|
49
50
|
nexus_config = nexus_defaults.merge(overrides_sym)
|
50
|
-
|
51
|
+
KPM::NexusFacade::RemoteFactory.create(nexus_config, ssl_verify, logger)
|
51
52
|
end
|
52
53
|
|
53
54
|
def nexus_defaults
|
54
55
|
{
|
55
|
-
|
56
|
-
|
56
|
+
url: 'https://oss.sonatype.org',
|
57
|
+
repository: 'releases'
|
57
58
|
}
|
58
59
|
end
|
59
60
|
|
60
61
|
protected
|
61
62
|
|
62
|
-
def pull_and_put_in_place(logger, coordinate_map, plugin_name, destination_path=nil, skip_top_dir=true, sha1_file=nil, force_download=false, verify_sha1=true, overrides={}, ssl_verify=true)
|
63
|
+
def pull_and_put_in_place(logger, coordinate_map, plugin_name, destination_path = nil, skip_top_dir = true, sha1_file = nil, force_download = false, verify_sha1 = true, overrides = {}, ssl_verify = true)
|
63
64
|
# Build artifact info
|
64
|
-
artifact_info = artifact_info(logger, coordinate_map, overrides, ssl_verify)
|
65
|
+
artifact_info = artifact_info(logger, coordinate_map, sha1_file, force_download, overrides, ssl_verify)
|
65
66
|
artifact_info[:plugin_name] = plugin_name
|
66
67
|
populate_fs_info(artifact_info, destination_path)
|
67
68
|
|
@@ -104,7 +105,7 @@ module KPM
|
|
104
105
|
logger.info " Starting download of #{coordinates} to #{tmp_destination_dir}"
|
105
106
|
|
106
107
|
downloaded_artifact_info = pull_and_verify(logger, artifact_info[:sha1], coordinates, tmp_destination_dir, sha1_file, verify_sha1, overrides, ssl_verify)
|
107
|
-
remove_old_default_bundles(coordinate_map,artifact_info,downloaded_artifact_info)
|
108
|
+
remove_old_default_bundles(coordinate_map, artifact_info, downloaded_artifact_info)
|
108
109
|
if artifact_info[:is_tgz]
|
109
110
|
artifact_info[:bundle_dir] = Utils.unpack_tgz(downloaded_artifact_info[:file_path], artifact_info[:dir_name], skip_top_dir)
|
110
111
|
FileUtils.rm downloaded_artifact_info[:file_path]
|
@@ -119,11 +120,11 @@ module KPM
|
|
119
120
|
end
|
120
121
|
|
121
122
|
# Logic similar than pull_and_put_in_place above
|
122
|
-
def pull_from_fs_and_put_in_place(logger, file_path, destination_path=nil)
|
123
|
+
def pull_from_fs_and_put_in_place(logger, file_path, destination_path = nil)
|
123
124
|
artifact_info = {
|
124
|
-
|
125
|
-
|
126
|
-
|
125
|
+
skipped: false,
|
126
|
+
repository_path: file_path,
|
127
|
+
is_tgz: file_path.end_with?('.tar.gz') || file_path.end_with?('.tgz')
|
127
128
|
}
|
128
129
|
|
129
130
|
populate_fs_info(artifact_info, destination_path)
|
@@ -148,7 +149,7 @@ module KPM
|
|
148
149
|
return false if artifact_info[:sha1].nil?
|
149
150
|
|
150
151
|
# If there is no such sha1_file, we don't skip
|
151
|
-
return false if sha1_file.nil? || !File.
|
152
|
+
return false if sha1_file.nil? || !File.exist?(sha1_file)
|
152
153
|
|
153
154
|
#
|
154
155
|
# At this point we have a valid sha1_file and a remote sha1
|
@@ -168,19 +169,25 @@ module KPM
|
|
168
169
|
end
|
169
170
|
end
|
170
171
|
|
171
|
-
def artifact_info(logger, coordinate_map, overrides={}, ssl_verify=true)
|
172
|
+
def artifact_info(logger, coordinate_map, sha1_file = nil, force_download = false, overrides = {}, ssl_verify = true)
|
172
173
|
info = {
|
173
|
-
|
174
|
+
skipped: false
|
174
175
|
}
|
175
176
|
|
177
|
+
sha1_checker = sha1_file ? Sha1Checker.from_file(sha1_file) : nil
|
178
|
+
|
176
179
|
coordinates = KPM::Coordinates.build_coordinates(coordinate_map)
|
177
180
|
begin
|
178
181
|
nexus_info = nexus_remote(overrides, ssl_verify, logger).get_artifact_info(coordinates)
|
179
182
|
rescue KPM::NexusFacade::ArtifactMalformedException => e
|
180
|
-
raise StandardError
|
183
|
+
raise StandardError, "Invalid coordinates #{coordinate_map}: #{e}"
|
181
184
|
rescue StandardError => e
|
182
|
-
logger.warn("Unable to retrieve coordinates #{coordinate_map}")
|
183
|
-
|
185
|
+
logger.warn("Unable to retrieve coordinates #{coordinate_map}: #{e}")
|
186
|
+
cached_coordinates = sha1_checker ? sha1_checker.artifact_info(coordinates) : nil
|
187
|
+
raise e if force_download || !cached_coordinates
|
188
|
+
|
189
|
+
# Use the cache
|
190
|
+
return cached_coordinates
|
184
191
|
end
|
185
192
|
|
186
193
|
xml = REXML::Document.new(nexus_info)
|
@@ -189,12 +196,14 @@ module KPM
|
|
189
196
|
info[:repository_path] = xml.elements['//repositoryPath'].text unless xml.elements['//repositoryPath'].nil?
|
190
197
|
info[:is_tgz] = info[:repository_path].end_with?('.tar.gz') || info[:repository_path].end_with?('.tgz')
|
191
198
|
|
199
|
+
sha1_checker.cache_artifact_info(coordinates, info) if sha1_checker
|
200
|
+
|
192
201
|
info
|
193
202
|
end
|
194
203
|
|
195
204
|
def update_destination_path(info, destination_path)
|
196
205
|
# In case LATEST was specified, use the actual version as the directory name
|
197
|
-
destination_path = KPM
|
206
|
+
destination_path = KPM.root if destination_path.nil?
|
198
207
|
plugin_dir, version_dir = File.split(destination_path)
|
199
208
|
destination_path = Pathname.new(plugin_dir).join(info[:version]).to_s if version_dir == 'LATEST' && !info[:version].nil?
|
200
209
|
destination_path
|
@@ -221,13 +230,14 @@ module KPM
|
|
221
230
|
destination_path
|
222
231
|
end
|
223
232
|
|
224
|
-
def pull_and_verify(logger, remote_sha1, coordinates, destination_dir, sha1_file, verify_sha1, overrides={}, ssl_verify=true)
|
233
|
+
def pull_and_verify(logger, remote_sha1, coordinates, destination_dir, sha1_file, verify_sha1, overrides = {}, ssl_verify = true)
|
225
234
|
info = nexus_remote(overrides, ssl_verify, logger).pull_artifact(coordinates, destination_dir)
|
226
235
|
|
227
236
|
# Always verify sha1 and if incorrect either throw or log when we are asked to bypass sha1 verification
|
228
237
|
verified = verify(logger, coordinates, info[:file_path], remote_sha1)
|
229
|
-
|
238
|
+
unless verified
|
230
239
|
raise ArtifactCorruptedException if verify_sha1
|
240
|
+
|
231
241
|
logger.warn("Skip sha1 verification for #{coordinates}")
|
232
242
|
end
|
233
243
|
|
@@ -248,13 +258,10 @@ module KPM
|
|
248
258
|
|
249
259
|
local_sha1 = Digest::SHA1.file(file_path).hexdigest
|
250
260
|
res = local_sha1 == remote_sha1
|
251
|
-
|
252
|
-
logger.warn("Sha1 verification failed for #{coordinates} : local_sha1 = #{local_sha1}, remote_sha1 = #{remote_sha1}")
|
253
|
-
end
|
261
|
+
logger.warn("Sha1 verification failed for #{coordinates} : local_sha1 = #{local_sha1}, remote_sha1 = #{remote_sha1}") unless res
|
254
262
|
res
|
255
263
|
end
|
256
264
|
|
257
|
-
|
258
265
|
# Magic methods...
|
259
266
|
|
260
267
|
def path_looks_like_a_directory(path)
|
@@ -265,12 +272,12 @@ module KPM
|
|
265
272
|
|
266
273
|
last_part = File.basename(path).downcase
|
267
274
|
|
268
|
-
%w
|
275
|
+
%w[.pom .xml .war .jar .xsd .tar.gz .tgz .gz .zip].each do |classic_file_extension|
|
269
276
|
return false if last_part.end_with?(classic_file_extension)
|
270
277
|
end
|
271
278
|
|
272
279
|
# Known magic files
|
273
|
-
%w
|
280
|
+
%w[root].each do |classic_filename|
|
274
281
|
return false if last_part == classic_filename
|
275
282
|
end
|
276
283
|
|
@@ -286,12 +293,9 @@ module KPM
|
|
286
293
|
|
287
294
|
existing_default_bundles.each do |bundle|
|
288
295
|
bundle_name = Utils.get_plugin_name_from_file_path(bundle)
|
289
|
-
is_downloaded = downloaded_default_bundles.index {|file_name| file_name.include? bundle_name}
|
290
|
-
unless is_downloaded.nil?
|
291
|
-
FileUtils.remove(bundle)
|
292
|
-
end
|
296
|
+
is_downloaded = downloaded_default_bundles.index { |file_name| file_name.include? bundle_name }
|
297
|
+
FileUtils.remove(bundle) unless is_downloaded.nil?
|
293
298
|
end
|
294
|
-
|
295
299
|
end
|
296
300
|
end
|
297
301
|
end
|
data/lib/kpm/base_installer.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
require 'zip'
|
3
5
|
|
4
6
|
module KPM
|
5
7
|
class BaseInstaller
|
6
|
-
|
7
8
|
LATEST_VERSION = 'LATEST'
|
8
9
|
SHA1_FILENAME = 'sha1.yml'
|
9
10
|
DEFAULT_BUNDLES_DIR = Pathname.new('/var').join('tmp').join('bundles').to_s
|
@@ -15,13 +16,13 @@ module KPM
|
|
15
16
|
@trace_logger = KPM::TraceLogger.new
|
16
17
|
end
|
17
18
|
|
18
|
-
def install_killbill_server(specified_group_id=nil, specified_artifact_id=nil, specified_packaging=nil, specified_classifier=nil, specified_version=nil, specified_webapp_path=nil,
|
19
|
+
def install_killbill_server(specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, specified_webapp_path = nil, bundles_dir = nil, force_download = false, verify_sha1 = true)
|
19
20
|
group_id = specified_group_id || KPM::BaseArtifact::KILLBILL_GROUP_ID
|
20
21
|
artifact_id = specified_artifact_id || KPM::BaseArtifact::KILLBILL_ARTIFACT_ID
|
21
22
|
packaging = specified_packaging || KPM::BaseArtifact::KILLBILL_PACKAGING
|
22
23
|
classifier = specified_classifier || KPM::BaseArtifact::KILLBILL_CLASSIFIER
|
23
24
|
version = specified_version || LATEST_VERSION
|
24
|
-
webapp_path = specified_webapp_path || KPM
|
25
|
+
webapp_path = specified_webapp_path || KPM.root
|
25
26
|
bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
|
26
27
|
sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}"
|
27
28
|
|
@@ -32,60 +33,55 @@ module KPM
|
|
32
33
|
|
33
34
|
@logger.debug("Installing Kill Bill server: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} webapp_path=#{webapp_path}")
|
34
35
|
artifact_info = KPM::KillbillServerArtifact.pull(@logger,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
36
|
+
group_id,
|
37
|
+
artifact_id,
|
38
|
+
packaging,
|
39
|
+
classifier,
|
40
|
+
version,
|
41
|
+
webapp_path,
|
42
|
+
sha1_file,
|
43
|
+
force_download,
|
44
|
+
verify_sha1,
|
45
|
+
@nexus_config,
|
46
|
+
@nexus_ssl_verify)
|
46
47
|
# store trace info to be returned as JSON by the KPM::Installer.install method
|
47
|
-
@trace_logger.add('killbill',
|
48
|
-
|
49
|
-
|
48
|
+
@trace_logger.add('killbill', nil,
|
49
|
+
artifact_info.merge('status' => (artifact_info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'),
|
50
|
+
:group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier))
|
50
51
|
end
|
51
52
|
|
52
|
-
def install_kaui(specified_group_id=nil, specified_artifact_id=nil, specified_packaging=nil, specified_classifier=nil, specified_version=nil, specified_webapp_path=nil,
|
53
|
+
def install_kaui(specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, specified_webapp_path = nil, bundles_dir = nil, force_download = false, verify_sha1 = true)
|
53
54
|
group_id = specified_group_id || KPM::BaseArtifact::KAUI_GROUP_ID
|
54
55
|
artifact_id = specified_artifact_id || KPM::BaseArtifact::KAUI_ARTIFACT_ID
|
55
56
|
packaging = specified_packaging || KPM::BaseArtifact::KAUI_PACKAGING
|
56
57
|
classifier = specified_classifier || KPM::BaseArtifact::KAUI_CLASSIFIER
|
57
58
|
version = specified_version || LATEST_VERSION
|
58
|
-
webapp_path = specified_webapp_path || KPM
|
59
|
+
webapp_path = specified_webapp_path || KPM.root
|
59
60
|
bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
|
60
61
|
sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}"
|
61
62
|
|
62
63
|
@logger.debug("Installing Kaui: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} webapp_path=#{webapp_path}")
|
63
64
|
artifact_info = KPM::KauiArtifact.pull(@logger,
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
65
|
+
group_id,
|
66
|
+
artifact_id,
|
67
|
+
packaging,
|
68
|
+
classifier,
|
69
|
+
version,
|
70
|
+
webapp_path,
|
71
|
+
sha1_file,
|
72
|
+
force_download,
|
73
|
+
verify_sha1,
|
74
|
+
@nexus_config,
|
75
|
+
@nexus_ssl_verify)
|
75
76
|
# store trace info to be returned as JSON by the KPM::Installer.install method
|
76
|
-
@trace_logger.add('kaui',
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
@trace_logger.add('kaui', nil,
|
78
|
+
artifact_info.merge('status' => (artifact_info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'),
|
79
|
+
:group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier))
|
81
80
|
end
|
82
81
|
|
83
|
-
def install_plugin(plugin_key, raw_kb_version=nil, specified_group_id=nil, specified_artifact_id=nil, specified_packaging=nil, specified_classifier=nil, specified_version=nil, bundles_dir=nil, specified_type=nil, force_download=false, verify_sha1=true, verify_jruby_jar=false)
|
84
|
-
|
82
|
+
def install_plugin(plugin_key, raw_kb_version = nil, specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, bundles_dir = nil, specified_type = nil, force_download = false, verify_sha1 = true, verify_jruby_jar = false)
|
85
83
|
# plugin_key needs to exist
|
86
|
-
if plugin_key.nil?
|
87
|
-
raise ArgumentError.new 'Aborting installation: User needs to specify a pluginKey'
|
88
|
-
end
|
84
|
+
raise ArgumentError, 'Aborting installation: User needs to specify a pluginKey' if plugin_key.nil?
|
89
85
|
|
90
86
|
# Lookup artifact and perform validation against input
|
91
87
|
looked_up_group_id, looked_up_artifact_id, looked_up_packaging, looked_up_classifier, looked_up_version, looked_up_type = KPM::PluginsDirectory.lookup(plugin_key, true, raw_kb_version)
|
@@ -95,21 +91,17 @@ module KPM
|
|
95
91
|
validate_installation_arg!(plugin_key, 'type', specified_type, looked_up_type)
|
96
92
|
validate_installation_arg!(plugin_key, 'classifier', specified_classifier, looked_up_classifier)
|
97
93
|
|
98
|
-
|
99
94
|
# If there is no entry in plugins_directory.yml and the group_id is not the killbill default group_id, the key provided must be a user key and must have a namespace
|
100
95
|
if looked_up_artifact_id.nil? &&
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
raise ArgumentError
|
96
|
+
specified_group_id != KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_GROUP_ID &&
|
97
|
+
specified_group_id != KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_GROUP_ID &&
|
98
|
+
plugin_key.split(':').size == 1
|
99
|
+
raise ArgumentError, "Aborting installation: pluginKey = #{plugin_key} does not exist in plugin_directory.yml so format of the key must have a user namespace (e.g namespace:key)"
|
105
100
|
end
|
106
101
|
|
107
|
-
|
108
102
|
# Specified parameters have always precedence except for the artifact_id (to map stripe to stripe-plugin)
|
109
103
|
artifact_id = looked_up_artifact_id || specified_artifact_id
|
110
|
-
if artifact_id.nil?
|
111
|
-
raise ArgumentError.new "Aborting installation: unable to lookup plugin #{specified_artifact_id}"
|
112
|
-
end
|
104
|
+
raise ArgumentError, "Aborting installation: unable to lookup plugin #{specified_artifact_id}" if artifact_id.nil?
|
113
105
|
|
114
106
|
bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
|
115
107
|
plugins_dir = bundles_dir.join('plugins')
|
@@ -136,10 +128,9 @@ module KPM
|
|
136
128
|
_, plugin_name = plugins_manager.get_plugin_key_and_name(plugin_key)
|
137
129
|
|
138
130
|
# Before we do the install we verify that the entry we have in the plugin_identifiers.json matches our current request
|
139
|
-
coordinate_map = {:
|
131
|
+
coordinate_map = { group_id: group_id, artifact_id: artifact_id, packaging: packaging, classifier: classifier }
|
140
132
|
validate_plugin_key!(plugins_dir, plugin_key, coordinate_map)
|
141
133
|
|
142
|
-
|
143
134
|
@logger.debug("Installing plugin: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} destination=#{destination}")
|
144
135
|
artifact_info = KPM::KillbillPluginArtifact.pull(@logger,
|
145
136
|
group_id,
|
@@ -156,8 +147,8 @@ module KPM
|
|
156
147
|
@nexus_ssl_verify)
|
157
148
|
# store trace info to be returned as JSON by the KPM::Installer.install method
|
158
149
|
@trace_logger.add('plugins', plugin_key,
|
159
|
-
|
160
|
-
|
150
|
+
artifact_info.merge('status' => (artifact_info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'),
|
151
|
+
:group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier))
|
161
152
|
|
162
153
|
# Update with resolved version
|
163
154
|
coordinate_map[:version] = artifact_info[:version]
|
@@ -169,14 +160,19 @@ module KPM
|
|
169
160
|
artifact_info
|
170
161
|
end
|
171
162
|
|
163
|
+
def install_plugin_from_fs(plugin_key, raw_file_path, name, version, bundles_dir = nil, type = 'java')
|
164
|
+
# Expand glob if needed
|
165
|
+
file_paths = Dir.glob(raw_file_path)
|
166
|
+
raise ArgumentError, "Cannot install plugin: no file found at #{raw_file_path}" if file_paths.empty?
|
167
|
+
raise ArgumentError, "Cannot install plugin: multiple files found at #{raw_file_path}" if file_paths.size > 1
|
168
|
+
|
169
|
+
file_path = file_paths[0]
|
172
170
|
|
173
|
-
def install_plugin_from_fs(plugin_key, file_path, name, version, bundles_dir=nil, type='java')
|
174
171
|
bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
|
175
172
|
plugins_dir = bundles_dir.join('plugins')
|
176
173
|
|
177
|
-
if version.nil?
|
178
|
-
|
179
|
-
end
|
174
|
+
version = Utils.get_version_from_file_path(file_path) if version.nil?
|
175
|
+
raise ArgumentError, 'Cannot install plugin: missing version' if version.nil?
|
180
176
|
|
181
177
|
if type.to_s == 'java'
|
182
178
|
plugin_name = name.nil? ? Utils.get_plugin_name_from_file_path(file_path) : name
|
@@ -194,28 +190,26 @@ module KPM
|
|
194
190
|
|
195
191
|
# store trace info to be returned as JSON by the KPM::Installer.install method
|
196
192
|
@trace_logger.add('plugins', plugin_key,
|
197
|
-
|
193
|
+
artifact_info.merge('status' => 'INSTALLED'))
|
198
194
|
|
199
195
|
artifact_info
|
200
196
|
end
|
201
197
|
|
202
|
-
def uninstall_plugin(plugin_name_or_key, plugin_version=nil, bundles_dir=nil)
|
198
|
+
def uninstall_plugin(plugin_name_or_key, plugin_version = nil, bundles_dir = nil)
|
203
199
|
bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
|
204
200
|
plugins_dir = bundles_dir.join('plugins')
|
205
201
|
|
206
202
|
plugins_manager = PluginsManager.new(plugins_dir, @logger)
|
207
203
|
|
208
204
|
plugin_key, plugin_name = plugins_manager.get_plugin_key_and_name(plugin_name_or_key)
|
209
|
-
if plugin_name.nil?
|
210
|
-
raise ArgumentError.new "Cannot uninstall plugin: Unknown plugin name or plugin key = #{plugin_name_or_key}"
|
211
|
-
end
|
205
|
+
raise ArgumentError, "Cannot uninstall plugin: Unknown plugin name or plugin key = #{plugin_name_or_key}" if plugin_name.nil?
|
212
206
|
|
213
207
|
modified = plugins_manager.uninstall(plugin_name, plugin_version || :all)
|
214
208
|
plugins_manager.remove_plugin_identifier_key(plugin_key)
|
215
209
|
modified
|
216
210
|
end
|
217
211
|
|
218
|
-
def install_default_bundles(bundles_dir, specified_version=nil, kb_version=nil, force_download=false, verify_sha1=true)
|
212
|
+
def install_default_bundles(bundles_dir, specified_version = nil, kb_version = nil, force_download = false, verify_sha1 = true)
|
219
213
|
group_id = 'org.kill-bill.billing'
|
220
214
|
artifact_id = 'killbill-platform-osgi-bundles-defaultbundles'
|
221
215
|
packaging = 'tar.gz'
|
@@ -223,7 +217,8 @@ module KPM
|
|
223
217
|
|
224
218
|
version = specified_version
|
225
219
|
if version.nil? || version == LATEST_VERSION
|
226
|
-
|
220
|
+
sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}"
|
221
|
+
info = KPM::KillbillServerArtifact.info(kb_version || LATEST_VERSION, sha1_file, force_download, verify_sha1, @nexus_config, @nexus_ssl_verify)
|
227
222
|
version = info['killbill-platform']
|
228
223
|
end
|
229
224
|
version ||= LATEST_VERSION
|
@@ -246,15 +241,13 @@ module KPM
|
|
246
241
|
@nexus_config,
|
247
242
|
@nexus_ssl_verify)
|
248
243
|
|
249
|
-
@trace_logger.add('default_bundles',
|
250
|
-
info.merge(
|
251
|
-
|
244
|
+
@trace_logger.add('default_bundles', nil,
|
245
|
+
info.merge('status' => (info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'),
|
246
|
+
:group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier))
|
252
247
|
|
253
248
|
# The special JRuby bundle needs to be called jruby.jar
|
254
249
|
# TODO .first - code smell
|
255
|
-
unless info[:skipped]
|
256
|
-
File.rename Dir.glob("#{destination}/killbill-platform-osgi-bundles-jruby-*.jar").first, destination.join('jruby.jar')
|
257
|
-
end
|
250
|
+
File.rename Dir.glob("#{destination}/killbill-platform-osgi-bundles-jruby-*.jar").first, destination.join('jruby.jar') unless info[:skipped]
|
258
251
|
|
259
252
|
info
|
260
253
|
end
|
@@ -262,21 +255,16 @@ module KPM
|
|
262
255
|
private
|
263
256
|
|
264
257
|
def validate_installation_arg!(plugin_key, arg_type, specified_arg, looked_up_arg)
|
265
|
-
|
266
258
|
# If nothing was specified, or if we don't find anything from the lookup, nothing to validate against
|
267
|
-
if specified_arg.nil? || looked_up_arg.nil?
|
268
|
-
return
|
269
|
-
end
|
259
|
+
return if specified_arg.nil? || looked_up_arg.nil?
|
270
260
|
|
271
|
-
if specified_arg.to_s != looked_up_arg.to_s
|
272
|
-
raise ArgumentError.new "Aborting installation for plugin_key #{plugin_key}: specified value #{specified_arg} for #{arg_type} does not match looked_up value #{looked_up_arg}"
|
273
|
-
end
|
261
|
+
raise ArgumentError, "Aborting installation for plugin_key #{plugin_key}: specified value #{specified_arg} for #{arg_type} does not match looked_up value #{looked_up_arg}" if specified_arg.to_s != looked_up_arg.to_s
|
274
262
|
end
|
275
263
|
|
276
264
|
def validate_plugin_key!(plugins_dir, plugin_key, coordinate_map)
|
277
265
|
plugins_manager = PluginsManager.new(plugins_dir, @logger)
|
278
266
|
res = plugins_manager.validate_plugin_identifier_key(plugin_key, coordinate_map)
|
279
|
-
raise ArgumentError
|
267
|
+
raise ArgumentError, "Failed to validate plugin key #{plugin_key}" unless res
|
280
268
|
end
|
281
269
|
|
282
270
|
def update_plugin_identifier(plugins_dir, plugin_key, type, coordinate_map, artifact_info)
|
@@ -288,7 +276,7 @@ module KPM
|
|
288
276
|
plugins_manager.add_plugin_identifier_key(plugin_key, plugin_name, type, coordinate_map)
|
289
277
|
end
|
290
278
|
|
291
|
-
def mark_as_active(plugins_dir, artifact_info,
|
279
|
+
def mark_as_active(plugins_dir, artifact_info, _artifact_id = nil)
|
292
280
|
# Mark this bundle as active
|
293
281
|
plugins_manager = PluginsManager.new(plugins_dir, @logger)
|
294
282
|
plugins_manager.set_active(artifact_info[:bundle_dir])
|
@@ -297,14 +285,14 @@ module KPM
|
|
297
285
|
def warn_if_jruby_jar_missing(bundles_dir)
|
298
286
|
platform_dir = bundles_dir.join('platform')
|
299
287
|
jruby_jar = platform_dir.join('jruby.jar')
|
300
|
-
if !File.
|
301
|
-
@logger.warn(" Missing installation for jruby.jar under #{platform_dir}. This is required for ruby plugin installation")
|
288
|
+
if !File.exist?(jruby_jar)
|
289
|
+
@logger.warn(" Missing installation for jruby.jar under #{platform_dir}. This is required for ruby plugin installation")
|
302
290
|
else
|
303
291
|
version = extract_jruby_jar_version(jruby_jar)
|
304
292
|
if version
|
305
293
|
@logger.info(" Detected jruby.jar version #{version}")
|
306
294
|
else
|
307
|
-
@logger.warn(" Failed to detect jruby.jar version for #{jruby_jar}")
|
295
|
+
@logger.warn(" Failed to detect jruby.jar version for #{jruby_jar}")
|
308
296
|
end
|
309
297
|
end
|
310
298
|
end
|
@@ -319,10 +307,9 @@ module KPM
|
|
319
307
|
if selected_entries && selected_entries.size == 1
|
320
308
|
zip_entry = selected_entries[0]
|
321
309
|
content = zip_entry.get_input_stream.read
|
322
|
-
return content.split("\n").select { |e| e.start_with?(
|
310
|
+
return content.split("\n").select { |e| e.start_with?('version') }[0].split('=')[1]
|
323
311
|
end
|
324
312
|
nil
|
325
313
|
end
|
326
|
-
|
327
314
|
end
|
328
315
|
end
|