kpm 0.0.15 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,8 +27,9 @@ module KPM
27
27
  :default => true,
28
28
  :desc => 'Validate sha1 sum'
29
29
  desc 'install config_file', 'Install Kill Bill server and plugins according to the specified YAML configuration file.'
30
- def install(config_file)
31
- Installer.from_file(config_file).install(options[:force_download], options[:verify_sha1])
30
+ def install(config_file=nil)
31
+ help = Installer.from_file(config_file).install(options[:force_download], options[:verify_sha1])
32
+ say help, :green unless help.nil?
32
33
  end
33
34
 
34
35
  method_option :destination,
@@ -226,6 +227,19 @@ module KPM
226
227
  say "Available versions: #{KauiArtifact.versions(options[:overrides], options[:ssl_verify]).to_a.join(', ')}", :green
227
228
  end
228
229
 
230
+ method_option :version,
231
+ :type => :string,
232
+ :default => 'LATEST',
233
+ :desc => 'Kill Bill version'
234
+ desc 'info', 'Describe information about a Kill Bill version'
235
+ def info
236
+ info = KillbillServerArtifact.info(options[:version],
237
+ options[:overrides],
238
+ options[:ssl_verify])
239
+
240
+ say "Dependencies for version #{options[:version]}\n " + (info.map {|k,v| "#{k} #{v}"}).join("\n "), :green
241
+ end
242
+
229
243
  private
230
244
 
231
245
  def logger
@@ -0,0 +1,62 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module KPM
5
+ class TomcatManager
6
+
7
+ DOWNLOAD_URL = 'https://s3.amazonaws.com/kb-binaries/apache-tomcat-7.0.42.tar.gz'
8
+
9
+ def initialize(tomcat_dir, logger)
10
+ @tomcat_dir = Pathname.new(tomcat_dir)
11
+ @logger = logger
12
+ end
13
+
14
+ def download
15
+ uri = URI.parse(DOWNLOAD_URL)
16
+
17
+ path = nil
18
+ Dir.mktmpdir do |dir|
19
+ file = Pathname.new(dir).join('tomcat.tar.gz')
20
+
21
+ @logger.info "Starting download of #{DOWNLOAD_URL} to #{file}"
22
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
23
+ File.open(file, 'wb+') do |file|
24
+ http.get(uri.path) do |body|
25
+ file.write(body)
26
+ end
27
+ end
28
+ end
29
+
30
+ path = Utils.unpack_tgz(file.to_s, @tomcat_dir, true)
31
+ end
32
+
33
+ @logger.info "Successful installation of #{DOWNLOAD_URL} to #{path}"
34
+ path
35
+ end
36
+
37
+ def setup
38
+ # Remove default webapps
39
+ %w(ROOT docs examples host-manager manager).each do |webapp|
40
+ FileUtils.rm_rf(@tomcat_dir.join('webapps').join(webapp))
41
+ end
42
+
43
+ # Update Root.xml
44
+ root_xml_dir = @tomcat_dir.join('conf').join('Catalina').join('localhost')
45
+ FileUtils.mkdir_p(root_xml_dir)
46
+ File.write(root_xml_dir.join('ROOT.xml'), '<Context></Context>')
47
+
48
+ # Setup default properties
49
+ setenv_sh_path = @tomcat_dir.join('bin').join('setenv.sh')
50
+ File.write(setenv_sh_path, 'export CATALINA_OPTS="$CATALINA_OPTS -XX:PermSize=512m -XX:MaxPermSize=1G -Xms1G -Xmx2G"')
51
+
52
+ @tomcat_dir.join('webapps').join('ROOT.war').to_s
53
+ end
54
+
55
+ def help
56
+ "Tomcat installed at #{@tomcat_dir}
57
+ Start script: #{@tomcat_dir.join('bin').join('startup.sh').to_s}
58
+ Stop script: #{@tomcat_dir.join('bin').join('shutdown.sh').to_s}
59
+ Logs: #{@tomcat_dir.join('logs').to_s}"
60
+ end
61
+ end
62
+ end
@@ -8,6 +8,7 @@ module KPM
8
8
  TAR_LONGLINK = '././@LongLink'
9
9
 
10
10
  def unpack_tgz(tar_gz_archive, destination, skip_top_dir=false)
11
+ top_dir = nil
11
12
  Gem::Package::TarReader.new(Zlib::GzipReader.open(tar_gz_archive)) do |tar|
12
13
  dest = nil
13
14
  tar.each do |entry|
@@ -22,16 +23,21 @@ module KPM
22
23
  FileUtils.mkdir_p dest, :mode => entry.header.mode, :verbose => false
23
24
  elsif entry.file?
24
25
  FileUtils.rm_rf dest if File.directory? dest
26
+ FileUtils.mkdir_p File.dirname(dest), :verbose => false
25
27
  File.open dest, "wb" do |f|
26
28
  f.print entry.read
27
29
  end
28
30
  FileUtils.chmod entry.header.mode, dest, :verbose => false
31
+ current_dir = File.dirname(dest)
32
+ # In case there are two top dirs, keep the last one by convention
33
+ top_dir = current_dir if (top_dir.nil? || top_dir.size >= current_dir.size)
29
34
  elsif entry.header.typeflag == '2' # Symlink
30
35
  File.symlink entry.header.linkname, dest
31
36
  end
32
37
  dest = nil
33
38
  end
34
39
  end
40
+ top_dir
35
41
  end
36
42
 
37
43
  def path_with_skipped_top_level_dir(path)
@@ -39,4 +45,4 @@ module KPM
39
45
  end
40
46
  end
41
47
  end
42
- end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module KPM
2
- VERSION = '0.0.15'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -23,8 +23,6 @@ describe KPM::BaseArtifact do
23
23
  # Verify the download happens when we set force_download
24
24
  test_download dir, nil, false, true
25
25
  end
26
-
27
-
28
26
  end
29
27
 
30
28
  # This test makes sure the top level directory is correctly verify_is_skipped
@@ -45,6 +43,8 @@ describe KPM::BaseArtifact do
45
43
  files_in_dir[0].should == info[:file_path] + '/killbill-payment-test'
46
44
 
47
45
  File.read(info[:file_path] + '/killbill-payment-test/1.8.7/killbill.properties').should == "mainClass=PaymentTest::PaymentPlugin\nrequire=payment_test\npluginType=PAYMENT\n"
46
+
47
+ info[:bundle_dir].should == info[:file_path] + '/killbill-payment-test/1.8.7'
48
48
  end
49
49
  end
50
50
 
@@ -64,6 +64,8 @@ describe KPM::BaseArtifact do
64
64
  files_in_dir.size.should == 20
65
65
 
66
66
  File.file?(info[:file_path] + '/killbill-osgi-bundles-jruby-0.11.3.jar').should be_true
67
+
68
+ info[:bundle_dir].should == info[:file_path]
67
69
  end
68
70
  end
69
71
 
@@ -24,6 +24,9 @@ describe KPM::Installer do
24
24
  'ruby' => [{
25
25
  'name' => 'payment-test-plugin',
26
26
  'version' => '1.8.7'
27
+ },
28
+ {
29
+ 'name' => 'stripe'
27
30
  }]
28
31
  },
29
32
  },
@@ -35,30 +38,40 @@ describe KPM::Installer do
35
38
  @logger)
36
39
 
37
40
  installer.install
41
+ check_installation(plugins_dir, kb_webapp_path, kaui_webapp_path)
38
42
 
39
- [
40
- plugins_dir,
41
- plugins_dir + '/platform',
42
- plugins_dir + '/plugins',
43
- plugins_dir + '/plugins/java',
44
- plugins_dir + '/plugins/java/analytics-plugin',
45
- plugins_dir + '/plugins/java/analytics-plugin/0.7.1',
46
- plugins_dir + '/plugins/ruby',
47
- plugins_dir + '/plugins/ruby/killbill-payment-test',
48
- plugins_dir + '/plugins/ruby/killbill-payment-test/1.8.7'
49
- ].each do |dir|
50
- File.directory?(dir).should be_true
51
- end
43
+ # Verify idempotency
44
+ installer.install
45
+ check_installation(plugins_dir, kb_webapp_path, kaui_webapp_path)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def check_installation(plugins_dir, kb_webapp_path, kaui_webapp_path)
52
+ [
53
+ plugins_dir,
54
+ plugins_dir + '/platform',
55
+ plugins_dir + '/plugins',
56
+ plugins_dir + '/plugins/java',
57
+ plugins_dir + '/plugins/java/analytics-plugin',
58
+ plugins_dir + '/plugins/java/analytics-plugin/0.7.1',
59
+ plugins_dir + '/plugins/ruby',
60
+ plugins_dir + '/plugins/ruby/killbill-payment-test',
61
+ plugins_dir + '/plugins/ruby/killbill-payment-test/1.8.7',
62
+ plugins_dir + '/plugins/ruby/killbill-stripe'
63
+ ].each do |dir|
64
+ File.directory?(dir).should be_true
65
+ end
52
66
 
53
- [
54
- kb_webapp_path,
55
- kaui_webapp_path,
56
- plugins_dir + '/platform/jruby.jar',
57
- plugins_dir + '/plugins/java/analytics-plugin/0.7.1/analytics-plugin-0.7.1.jar',
58
- plugins_dir + '/plugins/ruby/killbill-payment-test/1.8.7/killbill.properties'
59
- ].each do |file|
60
- File.file?(file).should be_true
61
- end
67
+ [
68
+ kb_webapp_path,
69
+ kaui_webapp_path,
70
+ plugins_dir + '/platform/jruby.jar',
71
+ plugins_dir + '/plugins/java/analytics-plugin/0.7.1/analytics-plugin-0.7.1.jar',
72
+ plugins_dir + '/plugins/ruby/killbill-payment-test/1.8.7/killbill.properties'
73
+ ].each do |file|
74
+ File.file?(file).should be_true
62
75
  end
63
76
  end
64
77
  end
@@ -28,4 +28,14 @@ describe KPM::KillbillServerArtifact do
28
28
  versions[0].should == '0.11.10'
29
29
  versions[1].should == '0.11.11'
30
30
  end
31
+
32
+ it 'should get dependencies information' do
33
+ info = KPM::KillbillServerArtifact.info('0.15.9')
34
+ info['killbill'].should == '0.15.9'
35
+ info['killbill-oss-parent'].should == '0.62'
36
+ info['killbill-api'].should == '0.27'
37
+ info['killbill-plugin-api'].should == '0.16'
38
+ info['killbill-commons'].should == '0.10'
39
+ info['killbill-platform'].should == '0.13'
40
+ end
31
41
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe KPM::TomcatManager do
4
+
5
+ before(:all) do
6
+ @logger = Logger.new(STDOUT)
7
+ @logger.level = Logger::INFO
8
+ end
9
+
10
+ it 'should be able to download and unpack tomcat' do
11
+ Dir.mktmpdir do |dir|
12
+ manager = KPM::TomcatManager.new(dir, @logger)
13
+
14
+ tomcat_path = manager.download
15
+ tomcat_path.should_not be_nil
16
+
17
+ root_war_path = manager.setup
18
+ root_war_path.should_not be_nil
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe KPM::BaseArtifact do
4
+
5
+ before(:all) do
6
+ @logger = Logger.new(STDOUT)
7
+ @logger.level = Logger::INFO
8
+ end
9
+
10
+ it 'should install from the filesystem' do
11
+ file_path = File.join(File.dirname(__FILE__), 'sha1_test.yml')
12
+
13
+ Dir.mktmpdir do |dir|
14
+ info = KPM::BaseArtifact.pull_from_fs(@logger, file_path, dir)
15
+
16
+ info[:skipped].should be_false
17
+ info[:is_tgz].should be_false
18
+ info[:repository_path].should == file_path
19
+ info[:dir_name].should == dir
20
+ info[:bundle_dir].should == dir
21
+ info[:file_name].should == 'sha1_test.yml'
22
+
23
+ files_in_dir = Dir[dir + '/*']
24
+ files_in_dir.size.should == 1
25
+ files_in_dir[0].should == info[:file_path]
26
+ end
27
+ end
28
+
29
+ it 'should build the fs info' do
30
+ # Kill Bill
31
+ check_fs_info('/opt/tomcat/webapps/ROOT.war',
32
+ '/path/to/killbill.war',
33
+ false,
34
+ '1.2.3',
35
+ '/opt/tomcat/webapps',
36
+ 'ROOT.war',
37
+ '/opt/tomcat/webapps/ROOT.war')
38
+
39
+ # Default bundles
40
+ check_fs_info('/var/tmp/bundles/platform',
41
+ '/path/to/bundles.tar.gz',
42
+ true,
43
+ '1.2.3',
44
+ '/var/tmp/bundles/platform',
45
+ nil,
46
+ '/var/tmp/bundles/platform')
47
+
48
+ # Java plugin
49
+ check_fs_info('/var/tmp/bundles/plugins/java/analytics-plugin/1.2.3',
50
+ '/path/to/analytics.jar',
51
+ false,
52
+ '1.2.3',
53
+ '/var/tmp/bundles/plugins/java/analytics-plugin/1.2.3',
54
+ 'analytics.jar',
55
+ '/var/tmp/bundles/plugins/java/analytics-plugin/1.2.3/analytics.jar')
56
+ check_fs_info('/var/tmp/bundles/plugins/java/analytics-plugin/LATEST',
57
+ '/path/to/analytics.jar',
58
+ false,
59
+ '1.2.3',
60
+ '/var/tmp/bundles/plugins/java/analytics-plugin/1.2.3',
61
+ 'analytics.jar',
62
+ '/var/tmp/bundles/plugins/java/analytics-plugin/1.2.3/analytics.jar')
63
+
64
+ # Ruby plugin
65
+ check_fs_info('/var/tmp/bundles/plugins/ruby',
66
+ '/path/to/stripe.tar.gz',
67
+ true,
68
+ '1.2.3',
69
+ '/var/tmp/bundles/plugins/ruby',
70
+ nil,
71
+ '/var/tmp/bundles/plugins/ruby')
72
+ end
73
+
74
+ private
75
+
76
+ def check_fs_info(specified_destination_path, repository_path, is_tgz, version, expected_dir_name, expected_file_name, expected_file_path)
77
+ info = {
78
+ :repository_path => repository_path,
79
+ :is_tgz => is_tgz,
80
+ :version => version
81
+ }
82
+
83
+ KPM::BaseArtifact.send('populate_fs_info', info, specified_destination_path)
84
+
85
+ info[:repository_path].should == repository_path
86
+ info[:is_tgz].should == is_tgz
87
+ info[:version].should == version
88
+ info[:dir_name].should == expected_dir_name
89
+ info[:file_name].should == expected_file_name
90
+ info[:file_path].should == expected_file_path
91
+ end
92
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe KPM::PluginsDirectory do
4
+
5
+ it 'should parse the plugins directory' do
6
+ directory = KPM::PluginsDirectory.all(false)
7
+ directory.size.should > 0
8
+ end
9
+
10
+ it 'should lookup plugins (legacy way)' do
11
+ group_id, artifact_id, packaging, classifier, version, type = KPM::PluginsDirectory.lookup('analytics', false)
12
+ group_id.should == 'org.kill-bill.billing.plugin.java'
13
+ artifact_id.should == 'analytics-plugin'
14
+ packaging.should == 'jar'
15
+ classifier.should be_nil
16
+ version.should == '2.0.2'
17
+ type.should == :java
18
+ end
19
+
20
+ it 'should lookup plugins' do
21
+ group_id, artifact_id, packaging, classifier, version, type = KPM::PluginsDirectory.lookup('analytics', false, '0.14')
22
+ group_id.should == 'org.kill-bill.billing.plugin.java'
23
+ artifact_id.should == 'analytics-plugin'
24
+ packaging.should == 'jar'
25
+ classifier.should be_nil
26
+ version.should == '1.0.3'
27
+ type.should == :java
28
+
29
+ group_id, artifact_id, packaging, classifier, version, type = KPM::PluginsDirectory.lookup('analytics', false, 'LATEST')
30
+ group_id.should == 'org.kill-bill.billing.plugin.java'
31
+ artifact_id.should == 'analytics-plugin'
32
+ packaging.should == 'jar'
33
+ classifier.should be_nil
34
+ version.should == 'LATEST'
35
+ type.should == :java
36
+
37
+ group_id, artifact_id, packaging, classifier, version, type = KPM::PluginsDirectory.lookup('analytics', false, '0.42')
38
+ group_id.should == 'org.kill-bill.billing.plugin.java'
39
+ artifact_id.should == 'analytics-plugin'
40
+ packaging.should == 'jar'
41
+ classifier.should be_nil
42
+ version.should == 'LATEST'
43
+ type.should == :java
44
+ end
45
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ describe KPM::PluginsManager do
4
+
5
+ before(:each) do
6
+ logger = Logger.new(STDOUT)
7
+ logger.level = Logger::INFO
8
+
9
+ @plugins_dir = Dir.mktmpdir
10
+ @manager = KPM::PluginsManager.new(@plugins_dir, logger)
11
+
12
+ @plugin_dir = Pathname.new(@plugins_dir).join('ruby').join('killbill-stripe')
13
+ FileUtils.mkdir_p(@plugin_dir)
14
+ FileUtils.mkdir_p(@plugin_dir.join('1.0.0'))
15
+ FileUtils.mkdir_p(@plugin_dir.join('2.0.0'))
16
+
17
+ File.exists?(@plugin_dir.join('ACTIVE')).should be_false
18
+ end
19
+
20
+ after(:each) do
21
+ FileUtils.remove_entry_secure @plugins_dir
22
+ end
23
+
24
+ it 'sets a path as active' do
25
+ @manager.set_active(@plugin_dir.join('1.0.0'))
26
+ File.exists?(@plugin_dir.join('ACTIVE')).should be_true
27
+ File.readlink(@plugin_dir.join('ACTIVE')).should == @plugin_dir.join('1.0.0').to_s
28
+
29
+ @manager.set_active(@plugin_dir.join('2.0.0'))
30
+ File.exists?(@plugin_dir.join('ACTIVE')).should be_true
31
+ File.readlink(@plugin_dir.join('ACTIVE')).should == @plugin_dir.join('2.0.0').to_s
32
+ end
33
+
34
+ it 'sets a plugin version as active' do
35
+ @manager.set_active('killbill-stripe', '2.0.0')
36
+ File.exists?(@plugin_dir.join('ACTIVE')).should be_true
37
+ File.readlink(@plugin_dir.join('ACTIVE')).should == @plugin_dir.join('2.0.0').to_s
38
+
39
+ @manager.set_active('killbill-stripe', '1.0.0')
40
+ File.exists?(@plugin_dir.join('ACTIVE')).should be_true
41
+ File.readlink(@plugin_dir.join('ACTIVE')).should == @plugin_dir.join('1.0.0').to_s
42
+ end
43
+
44
+ it 'uninstalls a plugin via a path' do
45
+ @manager.uninstall(@plugin_dir.join('1.0.0'))
46
+ check_state('1.0.0', false, true)
47
+ check_state('2.0.0', false, false)
48
+
49
+ @manager.uninstall(@plugin_dir.join('2.0.0'))
50
+ check_state('1.0.0', false, true)
51
+ check_state('2.0.0', false, true)
52
+ end
53
+
54
+ it 'uninstalls a plugin via name' do
55
+ @manager.uninstall('killbill-stripe', '1.0.0')
56
+ check_state('1.0.0', false, true)
57
+ check_state('2.0.0', false, false)
58
+
59
+ @manager.uninstall('killbill-stripe', '2.0.0')
60
+ check_state('1.0.0', false, true)
61
+ check_state('2.0.0', false, true)
62
+ end
63
+
64
+ it 'restarts a plugin via a path' do
65
+ @manager.restart(@plugin_dir.join('1.0.0'))
66
+ check_state('1.0.0', true, false)
67
+ check_state('2.0.0', false, false)
68
+
69
+ @manager.restart(@plugin_dir.join('2.0.0'))
70
+ check_state('1.0.0', true, false)
71
+ check_state('2.0.0', true, false)
72
+ end
73
+
74
+ it 'restarts a plugin via name' do
75
+ @manager.restart('killbill-stripe', '1.0.0')
76
+ check_state('1.0.0', true, false)
77
+ check_state('2.0.0', false, false)
78
+
79
+ @manager.restart('killbill-stripe', '2.0.0')
80
+ check_state('1.0.0', true, false)
81
+ check_state('2.0.0', true, false)
82
+ end
83
+
84
+ it 'guesses the plugin name' do
85
+ @manager.guess_plugin_name('tripe').should be_nil
86
+ # Short name
87
+ @manager.guess_plugin_name('stripe').should == 'killbill-stripe'
88
+ # Artifact id
89
+ @manager.guess_plugin_name('stripe-plugin').should == 'killbill-stripe'
90
+ # Plugin name (top directory in the .tar.gz)
91
+ @manager.guess_plugin_name('killbill-stripe').should == 'killbill-stripe'
92
+ end
93
+
94
+ private
95
+
96
+ def check_state(version, has_restart, has_stop)
97
+ File.exists?(@plugin_dir.join(version).join('tmp').join('restart.txt')).should == has_restart
98
+ File.exists?(@plugin_dir.join(version).join('tmp').join('stop.txt')).should == has_stop
99
+ end
100
+ end