class AemLookout::Sync
Attributes
filesystem_path[RW]
hostnames[RW]
jcr_path[RW]
log[RW]
Public Class Methods
new(options)
click to toggle source
# File lib/aem_lookout/sync.rb, line 31 def initialize(options) default_log = Logger.new(options.fetch(:output, STDOUT)) @log = options.fetch(:log, default_log) @hostnames = options.fetch(:hostnames).map {|hostname| Hostname.new(hostname) } @sling_initial_content = options.fetch(:sling_initial_content, false) @filesystem_path = options.fetch(:filesystem) @jcr_path = options.fetch(:jcr) rescue KeyError => e raise ArgumentError.new("#{e.message} (missing a hash argument)") end
run(options)
click to toggle source
# File lib/aem_lookout/sync.rb, line 25 def self.run(options) self.new(options).run end
Public Instance Methods
build_package()
click to toggle source
# File lib/aem_lookout/sync.rb, line 92 def build_package copy_content_to_package create_settings create_filter SlingInitialContentConverter.convert_package(package_path) if sling_initial_content? sleep 0.1 # just in case end
content_paths()
click to toggle source
Locals on the local filesystem to copy into the package
# File lib/aem_lookout/sync.rb, line 43 def content_paths if @content_paths.nil? paths = if filesystem_path.end_with?(".content.xml") Pathname(filesystem_path).parent.to_s elsif sling_initial_content? and filesystem_path.end_with?(".json") [filesystem_path, filesystem_path.gsub(/.json$/, "")].delete_if { |path| !File.exist?(path) } else filesystem_path end @content_paths = Array(paths) end @content_paths end
copy_content_to_package()
click to toggle source
# File lib/aem_lookout/sync.rb, line 100 def copy_content_to_package FileUtils.mkdir_p(target_content_path_root) content_paths.each do |content_path| log.info "Copying content from #{content_path} to target content path root" FileUtils.cp_r(content_path, target_content_path_root) end end
create_filter()
click to toggle source
# File lib/aem_lookout/sync.rb, line 113 def create_filter File.open(vault_config_path + "filter.xml", 'w') do |f| paths = filter_paths f.write(ERB.new(filter_template).result(binding)) end end
create_settings()
click to toggle source
# File lib/aem_lookout/sync.rb, line 108 def create_settings FileUtils.mkdir_p(vault_config_path) File.open(vault_config_path + "settings.xml", 'w') {|f| f.write(settings_template) } end
filter_paths()
click to toggle source
Paths in the package to install into the JCR
# File lib/aem_lookout/sync.rb, line 60 def filter_paths if @filter_paths.nil? paths = if jcr_path.end_with?(".content.xml") Pathname(jcr_path).parent.to_s elsif sling_initial_content? and jcr_path.end_with?(".json") jcr_path.gsub(/.json$/, "") else jcr_path end @filter_paths = Array(paths) end @filter_paths end
filter_template()
click to toggle source
# File lib/aem_lookout/sync.rb, line 177 def filter_template <<-EOF <?xml version="1.0" encoding="UTF-8"?> <workspaceFilter vesion="0.1"> <% paths.each do |path| %> <filter root="<%= path %>" mode="replace"/>\n<% end %> </workspaceFilter> EOF end
install_package()
click to toggle source
# File lib/aem_lookout/sync.rb, line 124 def install_package hostnames.map do |hostname| install_package_to_hostname(hostname) end end
install_package_multithreaded()
click to toggle source
# File lib/aem_lookout/sync.rb, line 130 def install_package_multithreaded threads = hostnames.map do |hostname| Thread.new do install_package_to_hostname(hostname) end end threads.each {|thread| thread.join } # wait for threads end
install_package_to_hostname(hostname)
click to toggle source
# File lib/aem_lookout/sync.rb, line 140 def install_package_to_hostname(hostname) log.info "Installing package at #{package_path} to #{hostname.url_without_credentials}" command = "#{AemLookout.vlt_executable} --credentials #{hostname.credentials} -v import #{hostname.url_without_credentials} #{package_path} /" Terminal.new(log).execute_command(command) end
jcr_root_path()
click to toggle source
# File lib/aem_lookout/sync.rb, line 158 def jcr_root_path @jcr_root ||= package_path + "jcr_root" end
log_elapsed_time()
click to toggle source
# File lib/aem_lookout/sync.rb, line 87 def log_elapsed_time elapsed_time = (Time.now.to_f - @start_time.to_f).round(2) log.info "Elapsed time: #{elapsed_time} seconds" end
package_path()
click to toggle source
# File lib/aem_lookout/sync.rb, line 154 def package_path @package_path ||= Pathname(Dir.mktmpdir("vlt-sync")) end
run()
click to toggle source
# File lib/aem_lookout/sync.rb, line 76 def run start_timer build_package install_package log_elapsed_time end
settings_template()
click to toggle source
# File lib/aem_lookout/sync.rb, line 166 def settings_template <<-EOF <vault version="0.1"> <ignore name=".svn"/> <ignore name=".gitignore"/> <ignore name=".DS_Store"/> </vault> EOF end
sling_initial_content?()
click to toggle source
# File lib/aem_lookout/sync.rb, line 162 def sling_initial_content? @sling_initial_content end
sling_initial_content_filter_paths_for(jcr_path)
click to toggle source
# File lib/aem_lookout/sync.rb, line 120 def sling_initial_content_filter_paths_for(jcr_path) end
start_timer()
click to toggle source
# File lib/aem_lookout/sync.rb, line 83 def start_timer @start_time = Time.now end
target_content_path_root()
click to toggle source
# File lib/aem_lookout/sync.rb, line 150 def target_content_path_root (jcr_root_path + jcr_path.gsub(/^\//, "")).parent end
vault_config_path()
click to toggle source
# File lib/aem_lookout/sync.rb, line 146 def vault_config_path package_path + "META-INF/vault" end