kpm 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ require 'json'
2
+
3
+ module KPM
4
+ class TraceLogger
5
+ def initialize
6
+ @trace = Hash.new
7
+ end
8
+
9
+ # Return JSON representation of the logs
10
+ def to_json
11
+ @trace.to_json
12
+ end
13
+
14
+ # Return String representation of the logs
15
+ def to_s
16
+ @trace.to_s
17
+ end
18
+
19
+ # Return HASH representation of the logs
20
+ def to_hash
21
+ @trace
22
+ end
23
+
24
+ def add(group=nil, key, message)
25
+ add_to_hash(group,key,message);
26
+ end
27
+
28
+ private
29
+ # This procedures will store the logs into a hash to be later returned
30
+ def add_to_hash(group=nil, key, message)
31
+
32
+ if group.nil? || key.nil?
33
+ add_with_key(group || key, message)
34
+ else
35
+ container_key = group.to_sym
36
+
37
+ @trace[container_key] ||= Hash.new
38
+ child_key = key.to_sym
39
+
40
+ unless @trace[container_key][child_key].nil?
41
+ child_is_an_array = @trace[container_key][child_key].kind_of?(Array)
42
+
43
+ old_message = nil
44
+ old_message = @trace[container_key][child_key] unless child_is_an_array
45
+ @trace[container_key][child_key] = [] unless child_is_an_array
46
+ @trace[container_key][child_key].push(old_message) unless old_message.nil?
47
+ @trace[container_key][child_key].push(message)
48
+ else
49
+ @trace[container_key][child_key] = message
50
+ end
51
+ end
52
+ end
53
+
54
+ def add_with_key(key, message)
55
+ child_key = key.to_sym
56
+
57
+ unless @trace[child_key].nil?
58
+ child_is_an_array = @trace[child_key].kind_of?(Array)
59
+
60
+ old_message = nil
61
+ old_message = @trace[child_key] unless child_is_an_array
62
+ @trace[child_key] = [] unless child_is_an_array
63
+ @trace[child_key].push(old_message) unless old_message.nil?
64
+ @trace[child_key].push(message)
65
+ else
66
+ @trace[child_key] = message
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/kpm/utils.rb CHANGED
@@ -43,6 +43,48 @@ module KPM
43
43
  def path_with_skipped_top_level_dir(path)
44
44
  Pathname(path).each_filename.to_a[1..-1].join(File::SEPARATOR)
45
45
  end
46
+
47
+ def peek_tgz_file_names(tar_gz_archive)
48
+ file_names = []
49
+ Gem::Package::TarReader.new(Zlib::GzipReader.open(tar_gz_archive)) do |tar|
50
+ tar.each do |entry|
51
+ if entry.file?
52
+ file_names.push entry.full_name
53
+ end
54
+ end
55
+ end
56
+
57
+ file_names
58
+ end
59
+
60
+ def get_plugin_name_from_file_path(file_path)
61
+ base = File.basename(file_path).to_s
62
+ ver = get_version_from_file_path(file_path)
63
+ ext = File.extname(base)
64
+
65
+ name = base.gsub(ext,'')
66
+ if ver.nil?
67
+ # this will remove SNAPSHOT and any dash that appear before it (ex --SNAPSHOT).
68
+ name = name.gsub(/((-+){,1}SNAPSHOT){,1}/,'')
69
+ last_dash = name.rindex('-')
70
+ name = name[0..last_dash]
71
+ else
72
+ name = name.gsub(ver,'')
73
+ end
74
+
75
+ name = name[0..name.length-2] if name[-1].match(/[a-zA-z]/).nil?
76
+ name
77
+ end
78
+
79
+ def get_version_from_file_path(file_path)
80
+ base = File.basename(file_path).to_s
81
+ ver = base.match(/(\d+)(\.(\d+)){,6}((-+){,1}SNAPSHOT){,1}/)
82
+
83
+ return ver if ver.nil?
84
+
85
+ ver[0]
86
+ end
87
+
46
88
  end
47
89
  end
48
90
  end
data/lib/kpm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module KPM
2
- VERSION = '0.5.3'
2
+ VERSION = '0.6.0'
3
3
  end
data/pom.xml CHANGED
@@ -26,7 +26,7 @@
26
26
  <groupId>org.kill-bill.billing.installer</groupId>
27
27
  <artifactId>kpm</artifactId>
28
28
  <packaging>pom</packaging>
29
- <version>0.5.3</version>
29
+ <version>0.6.0</version>
30
30
  <name>KPM</name>
31
31
  <url>http://github.com/killbill/killbill-cloud</url>
32
32
  <description>KPM: the Kill Bill Package Manager</description>
@@ -46,6 +46,26 @@ describe KPM::BaseArtifact do
46
46
  end
47
47
  end
48
48
 
49
+ it 'should be able to download and remove previous version artifacts' do
50
+ group_id = 'org.kill-bill.billing'
51
+ artifact_id = 'killbill-platform-osgi-bundles-defaultbundles'
52
+ packaging = 'tar.gz'
53
+ classifier = nil
54
+ version = '0.36.2'
55
+
56
+ second_bundle_version = '0.36.10'
57
+
58
+ Dir.mktmpdir do |dir|
59
+ first_take = KPM::BaseArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, dir)
60
+ File.file?(first_take[:file_path] + '/killbill-platform-osgi-bundles-jruby-0.36.2.jar').should be_true
61
+
62
+ second_take = KPM::BaseArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, second_bundle_version, dir)
63
+ File.file?(first_take[:file_path] + '/killbill-platform-osgi-bundles-jruby-0.36.2.jar').should be_false
64
+ File.file?(second_take[:file_path] + '/killbill-platform-osgi-bundles-jruby-0.36.10.jar').should be_true
65
+
66
+ end
67
+ end
68
+
49
69
 
50
70
  def test_download(dir, filename=nil, verify_is_skipped=false, force_download=false)
51
71
  path = filename.nil? ? dir : dir + '/' + filename
@@ -52,6 +52,21 @@ describe KPM::BaseInstaller do
52
52
  end
53
53
  end
54
54
 
55
+ it 'should extract plugin name from file path' do
56
+
57
+ [
58
+ {:file_path => '/Somewhere/xxx-foo/target/xxx-1.0.0.jar', :expected => 'xxx'},
59
+ {:file_path => '/Somewhere/xxx-foo/target/xxx-foo-bar-1.0.0.jar', :expected => 'xxx-foo-bar'},
60
+ {:file_path => '/Somewhere/xxx-foo/target/xxx-foo-1.0.0.jar', :expected => 'xxx-foo'},
61
+ {:file_path => '/Somewhere/xxx-foo/target/xxx-foo-1.0.0-SNAPSHOT.jar', :expected => 'xxx-foo'},
62
+ {:file_path => '/Somewhere/xxx-foo/target/xxx-foo-1.0.jar', :expected => 'xxx-foo'},
63
+ {:file_path => '/Somewhere/xxx-foo/target/xxx-foo-1.jar', :expected => 'xxx-foo'},
64
+ {:file_path => '/Somewhere/xxx-foo/target/xxx-foo-abc-SNAPSHOT.jar', :expected => 'xxx-foo'},
65
+ {:file_path => '/Somewhere/xxx-foo/target/xxx-foo-abc.jar', :expected => 'xxx-foo'}
66
+ ].each do |test|
67
+ KPM::Utils.get_plugin_name_from_file_path(test[:file_path]).should eq test[:expected]
68
+ end
69
+ end
55
70
 
56
71
  private
57
72
 
@@ -19,7 +19,11 @@ describe KPM::Installer do
19
19
  @logger)
20
20
 
21
21
  # No exception
22
- installer.install.should be_nil
22
+ response = nil
23
+ expect{ response = installer.install }.to_not raise_exception
24
+ response = JSON[response]
25
+ response['help'].should be_nil
26
+ response['killbill']['status'].should eq 'INSTALLED'
23
27
  end
24
28
  end
25
29
 
@@ -34,7 +38,11 @@ describe KPM::Installer do
34
38
  @logger)
35
39
 
36
40
  # No exception
37
- installer.install.should be_nil
41
+ response = nil
42
+ expect{ response = installer.install }.to_not raise_exception
43
+ response = JSON[response]
44
+ response['help'].should be_nil
45
+ response['kaui']['status'].should eq 'INSTALLED'
38
46
  end
39
47
  end
40
48
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe KPM::Migrations do
3
+ describe KPM::Migrations, :skip_me_if_nil => ENV['TOKEN'].nil? do
4
4
 
5
5
  context 'plugins' do
6
6
  it 'should be able to find migrations for a java plugin' do
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'rexml/document'
3
+
4
+ describe KPM::NexusFacade do
5
+
6
+ let(:coordinates_map){ {:version => '0.1.4',
7
+ :group_id => 'org.kill-bill.billing',
8
+ :artifact_id => 'killbill-platform-osgi-api',
9
+ :packaging => 'jar',
10
+ :classifier => nil} }
11
+ let(:coordinates_with_classifier_map){ {:version => '0.1.1',
12
+ :group_id => 'org.kill-bill.billing',
13
+ :artifact_id => 'killbill-platform-osgi-bundles-jruby',
14
+ :packaging => 'jar',
15
+ :classifier => 'javadoc'} }
16
+ let(:coordinates) { KPM::Coordinates.build_coordinates(coordinates_map)}
17
+ let(:coordinates_with_classifier) { KPM::Coordinates.build_coordinates(coordinates_with_classifier_map)}
18
+ let(:nexus_remote) { described_class::RemoteFactory.create(nil, true)}
19
+
20
+ it 'when searching for artifacts' do
21
+ response = nil
22
+ expect{ response = nexus_remote.search_for_artifacts(coordinates) }.not_to raise_exception
23
+ expect(REXML::Document.new(response).elements["//artifactId"].text).to eq(coordinates_map[:artifact_id])
24
+ end
25
+
26
+ it 'when searching for artifact with classifier' do
27
+ response = nil
28
+ expect{ response = nexus_remote.search_for_artifacts(coordinates_with_classifier) }.not_to raise_exception
29
+ expect(REXML::Document.new(response).elements["//artifactId"].text).to eq(coordinates_with_classifier_map[:artifact_id])
30
+ end
31
+
32
+ it 'when getting artifact info' do
33
+ response = nil
34
+ expect{ response = nexus_remote.get_artifact_info(coordinates) }.not_to raise_exception
35
+ expect(REXML::Document.new(response).elements["//version"].text).to eq(coordinates_map[:version])
36
+ end
37
+
38
+ it 'when getting artifact info with classifier' do
39
+ response = nil
40
+ expect{ response = nexus_remote.get_artifact_info(coordinates_with_classifier) }.not_to raise_exception
41
+ expect(REXML::Document.new(response).elements["//version"].text).to eq(coordinates_with_classifier_map[:version])
42
+ end
43
+
44
+ it 'when pull artifact' do
45
+ response = nil
46
+ destination = Dir.mktmpdir('artifact')
47
+ expect{ response = nexus_remote.pull_artifact(coordinates,destination) }.not_to raise_exception
48
+ destination = File.join(File.expand_path(destination), response[:file_name])
49
+ expect(File.exist?(destination)).to be_true
50
+ end
51
+
52
+ it 'when pull artifact with classifier' do
53
+ response = nil
54
+ destination = Dir.mktmpdir('artifact')
55
+ expect{ response = nexus_remote.pull_artifact(coordinates_with_classifier,destination) }.not_to raise_exception
56
+ destination = File.join(File.expand_path(destination), response[:file_name])
57
+ expect(File.exist?(destination)).to be_true
58
+ end
59
+
60
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ RSpec.configure do |config|
11
11
  config.color_enabled = true
12
12
  config.tty = true
13
13
  config.formatter = 'documentation'
14
+ config.filter_run_excluding :skip_me_if_nil => true
14
15
  end
15
16
 
16
17
  shared_context 'connection_setup' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kill Bill core team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-20 00:00:00.000000000 Z
11
+ date: 2017-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.6.21
27
- - !ruby/object:Gem::Dependency
28
- name: nexus_cli
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 4.1.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 4.1.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: thor
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +122,7 @@ files:
136
122
  - lib/kpm/cli.rb
137
123
  - lib/kpm/coordinates.rb
138
124
  - lib/kpm/database.rb
125
+ - lib/kpm/diagnostic_file.rb
139
126
  - lib/kpm/formatter.rb
140
127
  - lib/kpm/inspector.rb
141
128
  - lib/kpm/installer.rb
@@ -143,14 +130,24 @@ files:
143
130
  - lib/kpm/killbill_plugin_artifact.rb
144
131
  - lib/kpm/killbill_server_artifact.rb
145
132
  - lib/kpm/migrations.rb
133
+ - lib/kpm/nexus_helper/actions.rb
134
+ - lib/kpm/nexus_helper/nexus_api_calls_v2.rb
135
+ - lib/kpm/nexus_helper/nexus_facade.rb
146
136
  - lib/kpm/plugins_directory.rb
147
137
  - lib/kpm/plugins_directory.yml
148
138
  - lib/kpm/plugins_manager.rb
149
139
  - lib/kpm/sha1_checker.rb
150
140
  - lib/kpm/system.rb
141
+ - lib/kpm/system_helpers/cpu_information.rb
142
+ - lib/kpm/system_helpers/disk_space_information.rb
143
+ - lib/kpm/system_helpers/entropy_available.rb
144
+ - lib/kpm/system_helpers/memory_information.rb
145
+ - lib/kpm/system_helpers/os_information.rb
146
+ - lib/kpm/system_helpers/system_proxy.rb
151
147
  - lib/kpm/tasks.rb
152
148
  - lib/kpm/tenant_config.rb
153
149
  - lib/kpm/tomcat_manager.rb
150
+ - lib/kpm/trace_logger.rb
154
151
  - lib/kpm/uninstaller.rb
155
152
  - lib/kpm/utils.rb
156
153
  - lib/kpm/version.rb
@@ -166,6 +163,7 @@ files:
166
163
  - spec/kpm/remote/killbill_plugin_artifact_spec.rb
167
164
  - spec/kpm/remote/killbill_server_artifact_spec.rb
168
165
  - spec/kpm/remote/migrations_spec.rb
166
+ - spec/kpm/remote/nexus_facade_spec.rb
169
167
  - spec/kpm/remote/tenant_config_spec.rb
170
168
  - spec/kpm/remote/tenant_config_spec.yml
171
169
  - spec/kpm/remote/tomcat_manager_spec.rb