Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion : Wait for installer state to be ok before continuing. #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixed port '4502' should come from the "port" parameter -> see build_cfg method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but for that i needed to modify the 'build_client' function, which i did not want to do for this PR. It is mainly intended as a discussion entry-point and definitely not as a final clean-code PR.

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