class Aem::Deploy::Session
Attributes
Public Class Methods
Initialize the object @param [Hash] including :host, :user and :pass REQUIRED, optional :retry [Integer] which will retry failures x times. @raise [Error] if :host, :user and :pass are not passed on initialize
# File lib/aem/deploy/session.rb, line 14 def initialize(params) if [:host, :user, :pass].all? {|k| params.key?(k)} @host = params.fetch(:host) @user = params.fetch(:user) @pass = CGI.escape(params.fetch(:pass)) @retry = params.fetch(:retry).to_i unless params[:retry].nil? @protocol = params.fetch(:protocol) unless params[:protocol].nil? if @protocol.nil? @protocol = 'http' end else raise 'Hostname, User and Password are required' end end
Public Instance Methods
See Upload and Install methods for individual descriptions @param [String] path to the package for upload and installation. @return [Hash] installation message from crx
# File lib/aem/deploy/session.rb, line 32 def easy_install(package_path) upload_package(package_path) install_package end
Installs Package to CRX @param [Hash] Optionally install packages already on CRX uses :path key in options hash, if you know the path to the package on crx. @return [Hash] installation message from crx. @raise [Error] if server returns anything but success.
# File lib/aem/deploy/session.rb, line 59 def install_package(options = {}) if options[:path] @upload_path = options[:path] end install = RestClient::Request.execute(method: :post, url: "#{@protocol}://#{@user}:#{@pass}@#{@host}/crx/packmgr/service/.json#{@upload_path}", :timeout => 300, payload: {cmd: 'install', recursive: true} ) parse_response(install) rescue => error {error: error.to_s}.to_json if @retry puts 'retrying installation as there was a problem' retry unless (@retry -= 1).zero? end raise end
Parses message output from CRX @return [String] Recompile complete @raise [Error] if server returns anything but success.
# File lib/aem/deploy/session.rb, line 95 def parse_response(message) if JSON.parse(message)['success'] == true return " #{message}" elsif message.include? ("302 Found") return ' JSPs Recompiled' else raise " #{JSON.parse(message)}" end end
Recompiles JSPs @return [String] Recompile complete @raise [Error] if server returns anything but success.
# File lib/aem/deploy/session.rb, line 77 def recompile_jsps begin RestClient.post "#{@protocol}://#{@user}:#{@pass}@#{@host}/system/console/slingjsp", :cmd => 'recompile', :timeout => 120 rescue => error return {msg: 'JSPs recompiled'}.to_json rescue => error {error: error.to_s}.to_json if @retry puts 'retrying installation as there was a problem' retry unless (@retry -= 1).zero? end raise end end
:timeout => 90000000, :open_timeout => 90000000
Uploads Package to CRX @param [String] path to the package for upload and installation. @return [Hash] installation message from crx. @raise [Error] if server returns anything but success.
# File lib/aem/deploy/session.rb, line 42 def upload_package(package_path) upload = RestClient::Request.execute(method: :post, url: "#{@protocol}://#{@user}:#{@pass}@#{@host}/crx/packmgr/service/.json", :timeout => 300, payload: {cmd: 'upload', package: File.new(package_path, 'rb'), force: true} ) parse_response(upload) @upload_path = URI.encode(JSON.parse(upload)["path"]) rescue => error {error: error.to_s}.to_json if @retry puts 'retrying installation as there was a problem' retry unless (@retry -= 1).zero? end raise end