Skip to content

Commit

Permalink
Wait for installer state to be ok before continuing.
Browse files Browse the repository at this point in the history
  • Loading branch information
zipkid committed Feb 9, 2018
1 parent 41d6a3b commit 8375759
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AllCops:
Exclude:
- 'pkg/**/*'
- 'vendor/**/*'
TargetRubyVersion: 2.0
TargetRubyVersion: 2.2

Metrics/BlockLength:
Exclude:
Expand Down
43 changes: 43 additions & 0 deletions lib/puppet/provider/aem_crx_package/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,46 @@ def build_client
@client
end

def wait_for_install_ok
require 'uri'
require 'json'
require 'net/http'
retries ||= @resource[:retries]
retry_timeout = @resource[:retry_timeout]
host = 'http://localhost:4502'
path = '/system/sling/monitoring/mbeans/org/apache/sling/installer/Installer/Sling+OSGi+Installer.json'
uri = URI.parse(host + path)
request = Net::HTTP::Get.new(uri)
request.basic_auth(@resource[:username], @resource[:password])

# try http get of Sling+OSGi+Installer info...
# retry untill http 200 or Timeout
# check untill "Active":false and "ActiveResourceCount":0 or untill Timeout
begin
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(request)
end
data = JSON.parse(response.body)
# Maybe we will need to check for more than 1 ok result
# when installing some packages can trigger install of sub-packages...
if data['Active'] == true || data['ActiveResourceCount'] != 0
raise "Active: #{data['Active']} (req: false), ActiveResourceCount: #{data['ActiveResourceCount']} (req: 0)"
end
rescue Errno::EADDRNOTAVAIL, JSON::ParserError, RuntimeError => e
Puppet.info("wait_for_install_ok FAIL for Aem_crx_package[#{@resource[:pkg]}]: #{e.class} : #{e.message} :")
will_retry = (retries -= 1) >= 0
if will_retry
Puppet.debug("Waiting #{retry_timeout} seconds before retrying installer state query")
sleep retry_timeout
Puppet.debug("Retrying installer state query; remaining retries: #{retries}")
retry
end
raise
end
end

def find_package
wait_for_install_ok
client = build_client

path = "/etc/packages/#{@resource[:group]}/#{@resource[:pkg]}-.zip"
Expand Down Expand Up @@ -145,22 +184,26 @@ def find_version(ary)
end

def upload_package(install = false)
wait_for_install_ok
client = build_client
file = File.new(@resource[:source])
client.service_post(file, install: install)
end

def install_package
wait_for_install_ok
client = build_client
client.service_exec('install', @resource[:pkg], @resource[:group], @resource[:version])
end

def uninstall_package
wait_for_install_ok
client = build_client
client.service_exec('uninstall', @resource[:pkg], @resource[:group], @resource[:version])
end

def remove_package
wait_for_install_ok
client = build_client
client.service_exec('delete', @resource[:pkg], @resource[:group], @resource[:version])
end
Expand Down

0 comments on commit 8375759

Please sign in to comment.