kpm 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a60374d9426b71862a9dc7deba1f6b196af27ea
4
- data.tar.gz: 3e72b27242ce530e18eea45961f361ec70e73b0f
3
+ metadata.gz: 7a84528c544264bdd6db6123135d22b4af0ecb4d
4
+ data.tar.gz: 764686330376b941d7179507bc020133f551e97e
5
5
  SHA512:
6
- metadata.gz: 07dd7d2ad53197d3cca095c6c7a4cdc92e14bd7182d0da960611f43b229539b06723a46534b14fd660d8ef1cb9a476a9c4f24c4f54c1a9241bfca29d64d43e9b
7
- data.tar.gz: 9223ffad42ddadc56feb517b085ff9f1454bf57c12e56e2dd2bc4f43cb64ebc9ebb835f30f37f2ca5c9f950e961c09d0fc0cb199970b5ecd245517ec86083097
6
+ metadata.gz: da1d775e80d6c2e2a3e7b30ec155320521f1897cd410ff2ed460b1fb802526959caabd7736728ea77fd5ff9aa1efb34930abb95295dfeb9c03541e3a0acfe5b9
7
+ data.tar.gz: 2b52b1b175a2d73e061fad4ca6b02bbdc4175abdbc15995c4578f62b8b2d7dec784c1dbbeb63c88a4dbccab16fb729d30391b3aec615c64b25533c9f0ae8b7e4
data/lib/kpm/account.rb CHANGED
@@ -72,7 +72,7 @@ module KPM
72
72
  DEFAULT_DELIMITER = "|"
73
73
 
74
74
  def initialize(config_file = nil, killbill_api_credentials = nil, killbill_credentials = nil, killbill_url = nil,
75
- database_name = nil, database_credentials = nil, database_host = nil, data_delimiter = nil, logger = nil)
75
+ database_name = nil, database_credentials = nil, database_host = nil, database_port = nil, data_delimiter = nil, logger = nil)
76
76
  @killbill_api_key = KILLBILL_API_KEY
77
77
  @killbill_api_secrets = KILLBILL_API_SECRET
78
78
  @killbill_url = KILLBILL_URL
@@ -84,7 +84,7 @@ module KPM
84
84
 
85
85
 
86
86
  set_killbill_options(killbill_api_credentials,killbill_credentials,killbill_url)
87
- set_database_options(database_host,database_name,database_credentials,logger)
87
+ set_database_options(database_host,database_port,database_name,database_credentials,logger)
88
88
 
89
89
  load_config_from_file(config_file)
90
90
 
@@ -268,6 +268,7 @@ module KPM
268
268
  cols = line.strip.split(@delimiter)
269
269
 
270
270
  if cols_names.size != cols.size
271
+ @logger.warn "\e[32mWARNING!!! On #{table_name} table there is a mismatch on column count[#{cols.size}] versus header count[#{cols_names.size}]\e[0m"
271
272
  return nil
272
273
  end
273
274
 
@@ -276,7 +277,7 @@ module KPM
276
277
  cols_names.each_with_index do |col_name, index|
277
278
  sanitized_value = sanitize(table_name,col_name,cols[index], skip_payment_methods)
278
279
 
279
- if not sanitized_value.nil?
280
+ unless sanitized_value.nil?
280
281
  row << sanitized_value
281
282
  end
282
283
  end
@@ -479,13 +480,14 @@ module KPM
479
480
 
480
481
  end
481
482
 
482
- def set_database_options(database_host = nil, database_name = nil, database_credentials = nil, logger)
483
+ def set_database_options(database_host = nil, database_port = nil, database_name = nil, database_credentials = nil, logger)
483
484
 
484
485
  Database.set_logger(logger)
485
486
 
486
487
  Database.set_credentials(database_credentials[0],database_credentials[1]) unless database_credentials.nil?
487
488
  Database.set_database_name(database_name) unless database_name.nil?
488
489
  Database.set_host(database_host) unless database_host.nil?
490
+ Database.set_port(database_port) unless database_port.nil?
489
491
 
490
492
  Database.set_mysql_command_line
491
493
  end
data/lib/kpm/database.rb CHANGED
@@ -14,6 +14,7 @@ module KPM
14
14
  USERNAME = ENV['USERNAME'] || 'root'
15
15
  PASSWORD = ENV['PASSWORD'] || 'root'
16
16
  HOST = ENV['HOST'] || 'localhost'
17
+ PORT = ENV['PORT'] || '3306'
17
18
 
18
19
  COLUMN_NAME_POS = 3
19
20
 
@@ -26,6 +27,7 @@ module KPM
26
27
  @@password = PASSWORD
27
28
  @@database = DATABASE
28
29
  @@host = HOST
30
+ @@port = PORT
29
31
 
30
32
  def set_logger(logger)
31
33
  @@logger = logger
@@ -40,12 +42,16 @@ module KPM
40
42
  @@host = host
41
43
  end
42
44
 
45
+ def set_port(port)
46
+ @@port = port
47
+ end
48
+
43
49
  def set_database_name(database_name = nil)
44
50
  @@database = database_name
45
51
  end
46
52
 
47
53
  def set_mysql_command_line
48
- @@mysql_command_line = "mysql #{@@database} --host=#{@@host} --user=#{@@username} --password=#{@@password} "
54
+ @@mysql_command_line = "mysql #{@@database} --host=#{@@host} --port=#{@@port} --user=#{@@username} --password=#{@@password} "
49
55
  end
50
56
 
51
57
  def execute_insert_statement(table_name, query, qty_to_insert, table_data, record_id = nil)
@@ -58,10 +64,12 @@ module KPM
58
64
  File.open(STATEMENT_TMP_FILE,'w') do |s|
59
65
  s.puts query
60
66
  end
61
-
67
+
62
68
  response = `#{@@mysql_command_line} < "#{STATEMENT_TMP_FILE}" 2>&1`
63
69
 
64
70
  if response.include? 'ERROR'
71
+ @@logger.error "\e[91;1mTransaction that fails to be executed\e[0m"
72
+ @@logger.error "\e[91m#{query}\e[0m"
65
73
  raise Interrupt, "Importing table #{table_name}...... \e[91;1m#{response}\e[0m"
66
74
  end
67
75
 
@@ -89,17 +97,20 @@ module KPM
89
97
 
90
98
  tables.each_key do |table_name|
91
99
  table = tables[table_name]
92
- columns_names = table[:col_names].join(",").gsub(/'/,'')
100
+ if !table[:rows].nil? && table[:rows].size > 0
101
+ columns_names = table[:col_names].join(",").gsub(/'/,'')
93
102
 
94
- rows = []
95
- table[:rows].each do |row|
96
- rows << row.map{|value| value.is_a?(Symbol) ? value.to_s : "'#{value.to_s.gsub(/['"]/, "'" => "\\'", '"' => '\\"')}'" }.join(",")
97
- end
103
+ rows = []
104
+ table[:rows].each do |row|
105
+ rows << row.map{|value| value.is_a?(Symbol) ? value.to_s : "'#{value.to_s.gsub(/['"]/, "'" => "\\'", '"' => '\\"')}'" }.join(",")
106
+ end
107
+
108
+ value_data = rows.map{|row| "(#{row})" }.join(",")
98
109
 
99
- value_data = rows.map{|row| "(#{row})" }.join(",")
110
+ statements << {:query => get_insert_statement(table_name,columns_names,value_data, rows.size),
111
+ :qty_to_insert => rows.size, :table_name => table_name, :table_data => table}
100
112
 
101
- statements << {:query => get_insert_statement(table_name,columns_names,value_data, rows.size),
102
- :qty_to_insert => rows.size, :table_name => table_name, :table_data => table}
113
+ end
103
114
 
104
115
  end
105
116
 
@@ -25,7 +25,7 @@ module KPM
25
25
 
26
26
  def initialize(config_file = nil, killbill_api_credentials = nil, killbill_credentials = nil, killbill_url = nil,
27
27
  database_name = nil, database_credentials = nil, database_host = nil, kaui_web_path = nil,
28
- killbill_web_path = nil, logger = nil)
28
+ killbill_web_path = nil, bundles_dir = nil, logger = nil)
29
29
  @killbill_api_credentials = killbill_api_credentials
30
30
  @killbill_credentials = killbill_credentials
31
31
  @killbill_url = killbill_url
@@ -38,6 +38,7 @@ module KPM
38
38
  @logger = logger
39
39
  @original_logger_level = logger.level;
40
40
  @catalina_base = nil
41
+ @bundles_dir = bundles_dir
41
42
  end
42
43
 
43
44
  def export_data(account_id = nil, log_dir = nil)
@@ -58,7 +59,7 @@ module KPM
58
59
  zipFile.add(TENANT_FILE, tenant_export_file)
59
60
  zipFile.add(SYSTEM_FILE, system_export_file)
60
61
  zipFile.add(ACCOUNT_FILE, account_export_file) unless account_id.nil?
61
- zipFile.add(ZIP_LOG_FILE, log_files)
62
+ zipFile.add(ZIP_LOG_FILE, log_files) unless log_files.nil?
62
63
 
63
64
  end
64
65
 
@@ -99,7 +100,7 @@ module KPM
99
100
 
100
101
  @logger.info 'Retrieving system configuration'
101
102
  system = KPM::System.new
102
- export_data = system.information(nil, true, @config_file, @kaui_web_path, @killbill_web_path)
103
+ export_data = system.information(@bundles_dir, true, @config_file, @kaui_web_path, @killbill_web_path)
103
104
 
104
105
  get_system_catalina_base(export_data)
105
106
 
@@ -129,6 +130,12 @@ module KPM
129
130
  def get_log_files(log_dir)
130
131
 
131
132
  @logger.info 'Collecting log files'
133
+
134
+ if @catalina_base.nil? && log_dir.nil?
135
+ @logger.warn 'Unable to find Tomcat process, make sure to run kpm using the same user as the Tomcat process.'
136
+ return nil
137
+ end
138
+
132
139
  log_base = log_dir || (@catalina_base + File::Separator + 'logs')
133
140
  log_items = Dir.glob(log_base + File::Separator + '*')
134
141
 
@@ -149,7 +156,11 @@ module KPM
149
156
  # Helpers
150
157
 
151
158
  def get_system_catalina_base(export_data)
159
+ @catalina_base = nil
152
160
  system_json = JSON.parse(export_data)
161
+
162
+ return if system_json['java_system_information']['catalina.base'].nil?
163
+
153
164
  @catalina_base = system_json['java_system_information']['catalina.base']['value']
154
165
 
155
166
  end
data/lib/kpm/installer.rb CHANGED
@@ -18,8 +18,20 @@ module KPM
18
18
  def self.build_default_config(all_kb_versions=nil)
19
19
  latest_stable_version = get_kb_latest_stable_version(all_kb_versions)
20
20
 
21
- # Note: we assume no unstable version of Kaui is published today
22
- {'killbill' => {'version' => latest_stable_version.to_s, 'plugins' => {'ruby' => [{'name' => 'kpm'}]}}, 'kaui' => {'version' => 'LATEST'}}
21
+ {
22
+ 'killbill' => {
23
+ 'version' => latest_stable_version.to_s,
24
+ 'plugins' => {
25
+ 'ruby' => [
26
+ {'name' => 'kpm'}
27
+ ]
28
+ }
29
+ },
30
+ 'kaui' => {
31
+ # Note: we assume no unstable version of Kaui is published today
32
+ 'version' => 'LATEST'
33
+ }
34
+ }
23
35
  end
24
36
 
25
37
  def self.get_kb_latest_stable_version(all_kb_versions=nil)
@@ -16,7 +16,7 @@
16
16
  :0.15: 0.2.1
17
17
  :0.16: 0.3.2
18
18
  :0.17: 0.4.10
19
- :0.18: 0.5.5
19
+ :0.18: 0.5.7
20
20
  :require:
21
21
  - :org.killbill.billing.plugin.adyen.merchantAccount
22
22
  - :org.killbill.billing.plugin.adyen.username
@@ -30,6 +30,7 @@
30
30
  :0.16: 3.0.2
31
31
  :0.17: 4.0.5
32
32
  :0.18: 4.2.3
33
+ :0.19: 5.0.0
33
34
  :avatax:
34
35
  :type: :java
35
36
  :versions:
@@ -63,7 +64,7 @@
63
64
  :0.14: 1.0.0
64
65
  :0.15: 3.3.0
65
66
  :0.16: 4.0.12
66
- :0.18: 5.2.2
67
+ :0.18: 5.2.4
67
68
  :require:
68
69
  - :login
69
70
  - :password
@@ -138,7 +139,7 @@
138
139
  :type: :ruby
139
140
  :versions:
140
141
  :0.16: 0.0.2
141
- :0.18: 0.1.5
142
+ :0.18: 0.1.8
142
143
  :require:
143
144
  - :login
144
145
  - :password
@@ -157,7 +158,7 @@
157
158
  :versions:
158
159
  :0.16: 0.0.1
159
160
  :0.17: 0.1.0
160
- :0.18: 0.2.2
161
+ :0.18: 0.2.4
161
162
  :paypal:
162
163
  :type: :ruby
163
164
  :artifact_id: paypal-express-plugin
@@ -165,7 +166,7 @@
165
166
  :0.14: 2.0.0
166
167
  :0.15: 3.0.0
167
168
  :0.16: 4.1.7
168
- :0.18: 5.0.5
169
+ :0.18: 5.0.6
169
170
  :require:
170
171
  - :signature
171
172
  - :login
data/lib/kpm/system.rb CHANGED
@@ -226,7 +226,7 @@ module KPM
226
226
 
227
227
  yaml_file = kaui_search_default_dir + File::SEPARATOR + 'WEB-INF' + File::SEPARATOR + 'version.yml'
228
228
  unless Dir[yaml_file][0].nil?
229
- yml_data = YAML::load_file(yaml_file)
229
+ yml_data = YAML::load_file(Dir[yaml_file][0])
230
230
 
231
231
  version = yml_data['version']
232
232
  end
@@ -310,6 +310,15 @@ module KPM
310
310
 
311
311
  end
312
312
 
313
+ return apache_tomcat_pid unless apache_tomcat_pid.nil?
314
+
315
+ jcmd = ( ENV['JAVA_HOME'] || '/**' ) + File::Separator + 'bin' + File::Separator + 'jcmd'
316
+ jcmd = Dir[jcmd][0]
317
+ return nil if jcmd.nil?
318
+
319
+ apache_tomcat_pid = `#{jcmd} | awk '/org.apache.catalina/' | cut -d ' ' -f 1`.gsub("\n",'')
320
+ return nil if apache_tomcat_pid.nil? || apache_tomcat_pid.empty?
321
+
313
322
  apache_tomcat_pid
314
323
  end
315
324
 
data/lib/kpm/tasks.rb CHANGED
@@ -490,6 +490,10 @@ module KPM
490
490
  :type => :string,
491
491
  :default => nil,
492
492
  :desc => 'Database Host name'
493
+ method_option :database_port,
494
+ :type => :string,
495
+ :default => nil,
496
+ :desc => 'Database Host name'
493
497
  desc 'account', 'export/import accounts'
494
498
  def account
495
499
  logger.info 'Please wait processing the request!!!'
@@ -525,7 +529,7 @@ module KPM
525
529
 
526
530
 
527
531
  account = KPM::Account.new(config_file || options[:config_file],options[:killbill_api_credentials],options[:killbill_credentials],
528
- options[:killbill_url],options[:database_name],options[:database_credentials],options[:database_host],options[:data_delimiter], logger)
532
+ options[:killbill_url],options[:database_name],options[:database_credentials],options[:database_host], options[:database_port],options[:data_delimiter], logger)
529
533
  export_file = nil
530
534
  round_trip_export_import = false
531
535
 
@@ -643,6 +647,10 @@ module KPM
643
647
  :type => :string,
644
648
  :default => nil,
645
649
  :desc => 'Path for the killbill web app'
650
+ method_option :bundles_dir,
651
+ :type => :string,
652
+ :default => nil,
653
+ :desc => 'A different folder other than the default bundles directory.'
646
654
  desc 'diagnostic', 'exports and \'zips\' the account data, system, logs and tenant configurations'
647
655
  def diagnostic
648
656
  logger.info 'Please wait processing the request!!!'
@@ -681,7 +689,7 @@ module KPM
681
689
 
682
690
  diagnostic = KPM::DiagnosticFile.new(options[:config_file],options[:killbill_api_credentials],options[:killbill_credentials],
683
691
  options[:killbill_url],options[:database_name],options[:database_credentials],
684
- options[:database_host], options[:kaui_web_path], options[:killbill_web_path],logger)
692
+ options[:database_host], options[:kaui_web_path], options[:killbill_web_path], options[:bundles_dir],logger)
685
693
  diagnostic.export_data(options[:account_export], options[:log_dir])
686
694
 
687
695
  rescue Exception => e
@@ -47,7 +47,8 @@ module KPM
47
47
 
48
48
  # Setup default properties
49
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"')
50
+
51
+ File.write(setenv_sh_path, "export CATALINA_OPTS=\"$CATALINA_OPTS #{default_java_properties}\"")
51
52
 
52
53
  @tomcat_dir.join('webapps').join('ROOT.war').to_s
53
54
  end
@@ -58,5 +59,35 @@ Start script: #{@tomcat_dir.join('bin').join('startup.sh').to_s}
58
59
  Stop script: #{@tomcat_dir.join('bin').join('shutdown.sh').to_s}
59
60
  Logs: #{@tomcat_dir.join('logs').to_s}"
60
61
  end
62
+
63
+ private
64
+
65
+ def default_java_properties
66
+ <<HEREDOC.gsub(/\s+/, ' ').strip
67
+ -server
68
+ -showversion
69
+ -XX:+PrintCommandLineFlags
70
+ -XX:+UseCodeCacheFlushing
71
+ -XX:PermSize=512m
72
+ -XX:MaxPermSize=1G
73
+ -Xms1G
74
+ -Xmx2G
75
+ -XX:+CMSClassUnloadingEnabled
76
+ -XX:-OmitStackTraceInFastThrow
77
+ -XX:+UseParNewGC
78
+ -XX:+UseConcMarkSweepGC
79
+ -XX:+CMSConcurrentMTEnabled
80
+ -XX:+CMSParallelRemarkEnabled
81
+ -XX:+UseCMSInitiatingOccupancyOnly
82
+ -XX:CMSInitiatingOccupancyFraction=70
83
+ -XX:+ScavengeBeforeFullGC
84
+ -XX:+CMSScavengeBeforeRemark
85
+ -XX:NewSize=600m
86
+ -XX:MaxNewSize=900m
87
+ -XX:SurvivorRatio=10
88
+ -XX:+DisableExplicitGC
89
+ -Djava.security.egd=file:/dev/./urandom
90
+ HEREDOC
91
+ end
61
92
  end
62
93
  end
data/lib/kpm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module KPM
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
data/packaging/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'kpm'
3
+ gem 'kpm', '~> VERSION'
4
4
 
5
5
  group :development do
6
6
  gem 'rake'
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.6.0</version>
29
+ <version>0.6.1</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>
@@ -6,9 +6,10 @@ describe KPM::Account do
6
6
  include_context 'connection_setup'
7
7
 
8
8
  let(:db_host) {'localhost'}
9
+ let(:db_port) {'3306'}
9
10
  let(:account_class) { described_class.new(nil,[killbill_api_key,killbill_api_secrets],
10
11
  [killbill_user, killbill_password],url,
11
- db_name, [db_username, db_password],db_host,nil,logger)}
12
+ db_name, [db_username, db_password],db_host,db_port,nil,logger)}
12
13
  let(:dummy_account_id) {SecureRandom.uuid}
13
14
  let(:account_id_invalid) {SecureRandom.uuid}
14
15
  let(:dummy_data) {
data/tasks/package.rake CHANGED
@@ -1,5 +1,6 @@
1
1
  # For Bundler.with_clean_env
2
2
  require 'bundler/setup'
3
+ require 'yaml'
3
4
 
4
5
  PACKAGE_NAME = 'kpm'
5
6
 
@@ -36,7 +37,10 @@ namespace :package do
36
37
  end
37
38
 
38
39
  desc 'Install gems to local directory'
39
- task :bundle_install do
40
+ task :bundle_install => [:clean] do
41
+ # abort if version packaging does not exist on repository
42
+ abort "KPM #{VERSION} does not exists in the repository." unless gem_exists?
43
+
40
44
  # Note! Must match TRAVELING_RUBY_VERSION above
41
45
  expected_ruby_version = TRAVELING_RUBY_VERSION.split('-')[-1]
42
46
  if RUBY_VERSION !~ /#{Regexp.quote(expected_ruby_version)}/
@@ -45,6 +49,7 @@ namespace :package do
45
49
  sh 'rm -rf packaging/tmp'
46
50
  sh 'mkdir -p packaging/tmp'
47
51
  sh 'cp packaging/Gemfile packaging/tmp/'
52
+ sh "sed -i 's/VERSION/#{VERSION}/g' packaging/tmp/Gemfile"
48
53
 
49
54
  sh "rm -rf packaging/vendor/ruby/#{expected_ruby_version}/bundler" # if multiple clones of same repo, may load in wrong one
50
55
 
@@ -112,3 +117,11 @@ def download_runtime(target)
112
117
  sh 'mkdir -p packaging && cd packaging && curl -L -O --fail ' +
113
118
  "https://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}.tar.gz"
114
119
  end
120
+
121
+ def gem_exists?
122
+ response = `gem specification 'kpm' -r -v #{VERSION} 2>&1`
123
+ return false if response.nil?
124
+
125
+ specification = YAML::load(response)
126
+ specification.instance_of?(Gem::Specification)
127
+ end
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.6.0
4
+ version: 0.6.1
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-08-10 00:00:00.000000000 Z
11
+ date: 2018-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline