Class: RubyAem::Resources::Package
- Inherits:
-
Object
- Object
- RubyAem::Resources::Package
- Defined in:
- lib/ruby_aem/resources/package.rb
Overview
Package class contains API calls related to managing an AEM package.
Instance Method Summary collapse
-
#activate_filter(ignore_deactivated, modified_only) ⇒ Object
Activate all paths within a package filter.
-
#build ⇒ Object
Build the package.
-
#create ⇒ Object
Create the package.
-
#delete ⇒ Object
Delete the package.
-
#delete_wait_until_ready(opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object
Delete the package and wait until the package status states it is not uploaded.
-
#download(file_path) ⇒ Object
Download the package to a specified directory.
-
#get_filter ⇒ Object
Get the package filter value.
-
#initialize(client, group_name, package_name, package_version) ⇒ Object
constructor
Initialise a package.
-
#install(opts = { recursive: true }) ⇒ Object
Install the package without waiting until the package status states it is installed.
-
#install_wait_until_ready(opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object
Install the package and wait until the package status states it is installed.
-
#is_installed ⇒ Object
Check if this package is installed.
-
#is_uploaded ⇒ Object
Check if this package is uploaded.
-
#list_all ⇒ Object
List all packages available in AEM instance.
-
#replicate ⇒ Object
Replicate the package.
-
#update(filter) ⇒ Object
Update the package with specific filter.
-
#upload(file_path, opts = { force: true }) ⇒ Object
Upload the package without waiting until the package status states it is uploaded.
-
#upload_wait_until_ready(file_path, opts = { force: true, _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object
Upload the package and wait until the package status states it is uploaded.
Constructor Details
#initialize(client, group_name, package_name, package_version) ⇒ Object
Initialise a package. Package name and version will then be used to construct the package file in the filesystem. E.g. package name 'somepackage' with version '1.2.3' will translate to somepackage-1.2.3.zip in the filesystem.
33 34 35 36 37 38 39 40 |
# File 'lib/ruby_aem/resources/package.rb', line 33 def initialize(client, group_name, package_name, package_version) @client = client @call_params = { group_name: group_name, package_name: package_name, package_version: package_version } end |
Instance Method Details
#activate_filter(ignore_deactivated, modified_only) ⇒ Object
Activate all paths within a package filter. Returns an array of results:
-
the first result is the result from retrieving filter paths
-
the rest of the results are the results from activating the filter paths, one result for each activation
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ruby_aem/resources/package.rb', line 133 def activate_filter(ignore_deactivated, modified_only) result = get_filter() results = [result] result.data.each { |filter_path| path = RubyAem::Resources::Path.new(@client, filter_path) results.push(path.activate(ignore_deactivated, modified_only)) } results end |
#build ⇒ Object
Build the package.
69 70 71 |
# File 'lib/ruby_aem/resources/package.rb', line 69 def build() @client.call(self.class, __callee__.to_s, @call_params) end |
#create ⇒ Object
Create the package.
45 46 47 |
# File 'lib/ruby_aem/resources/package.rb', line 45 def create() @client.call(self.class, __callee__.to_s, @call_params) end |
#delete ⇒ Object
Delete the package.
62 63 64 |
# File 'lib/ruby_aem/resources/package.rb', line 62 def delete() @client.call(self.class, __callee__.to_s, @call_params) end |
#delete_wait_until_ready(opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object
Delete the package and wait until the package status states it is not uploaded.
-
_retries: retries library's options (www.rubydoc.info/gems/retries/0.0.5#Usage), restricted to max_trie, base_sleep_seconds, max_sleep_seconds
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/ruby_aem/resources/package.rb', line 271 def delete_wait_until_ready( opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) opts[:_retries] ||= {} opts[:_retries][:max_tries] ||= 30 opts[:_retries][:base_sleep_seconds] ||= 2 opts[:_retries][:max_sleep_seconds] ||= 2 # ensure integer retries setting (Puppet 3 passes numeric string) opts[:_retries][:max_tries] = opts[:_retries][:max_tries].to_i opts[:_retries][:base_sleep_seconds] = opts[:_retries][:base_sleep_seconds].to_i opts[:_retries][:max_sleep_seconds] = opts[:_retries][:max_sleep_seconds].to_i result = delete() with_retries(:max_tries => opts[:_retries][:max_tries], :base_sleep_seconds => opts[:_retries][:base_sleep_seconds], :max_sleep_seconds => opts[:_retries][:max_sleep_seconds]) { |retries_count| check_result = is_uploaded() puts 'Delete check #%d: %s - %s' % [retries_count, !check_result.data, check_result.] if check_result.data == true raise StandardError.new(check_result.) end } result end |
#download(file_path) ⇒ Object
Download the package to a specified directory.
97 98 99 100 |
# File 'lib/ruby_aem/resources/package.rb', line 97 def download(file_path) @call_params[:file_path] = file_path @client.call(self.class, __callee__.to_s, @call_params) end |
#get_filter ⇒ Object
Get the package filter value. Filter value is stored as result data as an array of paths.
121 122 123 |
# File 'lib/ruby_aem/resources/package.rb', line 121 def get_filter() @client.call(self.class, __callee__.to_s, @call_params) end |
#install(opts = { recursive: true }) ⇒ Object
Install the package without waiting until the package status states it is installed.
-
recursive: if true then subpackages will also be installed, false otherwise
78 79 80 81 82 83 |
# File 'lib/ruby_aem/resources/package.rb', line 78 def install(opts = { recursive: true }) @call_params = @call_params.merge(opts) @client.call(self.class, __callee__.to_s, @call_params) end |
#install_wait_until_ready(opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object
Install the package and wait until the package status states it is installed.
-
_retries: retries library's options (www.rubydoc.info/gems/retries/0.0.5#Usage), restricted to max_trie, base_sleep_seconds, max_sleep_seconds
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/ruby_aem/resources/package.rb', line 237 def install_wait_until_ready( opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) opts[:_retries] ||= {} opts[:_retries][:max_tries] ||= 30 opts[:_retries][:base_sleep_seconds] ||= 2 opts[:_retries][:max_sleep_seconds] ||= 2 # ensure integer retries setting (Puppet 3 passes numeric string) opts[:_retries][:max_tries] = opts[:_retries][:max_tries].to_i opts[:_retries][:base_sleep_seconds] = opts[:_retries][:base_sleep_seconds].to_i opts[:_retries][:max_sleep_seconds] = opts[:_retries][:max_sleep_seconds].to_i result = install() with_retries(:max_tries => opts[:_retries][:max_tries], :base_sleep_seconds => opts[:_retries][:base_sleep_seconds], :max_sleep_seconds => opts[:_retries][:max_sleep_seconds]) { |retries_count| check_result = is_installed() puts 'Install check #%d: %s - %s' % [retries_count, check_result.data, check_result.] if check_result.data == false raise StandardError.new(check_result.) end } result end |
#is_installed ⇒ Object
Check if this package is installed. True result data indicates that the package is installed, false otherwise.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/ruby_aem/resources/package.rb', line 176 def is_installed() packages = list_all().data package = packages.xpath("//packages/package[group=\"#{@call_params[:group_name]}\" and name=\"#{@call_params[:package_name]}\" and version=\"#{@call_params[:package_version]}\"]") last_unpacked_by = package.xpath('lastUnpackedBy') if not ['', '<lastUnpackedBy/>', '<lastUnpackedBy>null</lastUnpackedBy>'].include? last_unpacked_by.to_s = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is installed" is_installed = true else = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is not installed" is_installed = false end result = RubyAem::Result.new(, nil) result.data = is_installed result end |
#is_uploaded ⇒ Object
Check if this package is uploaded. True result data indicates that the package is uploaded, false otherwise.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/ruby_aem/resources/package.rb', line 155 def is_uploaded() packages = list_all().data package = packages.xpath("//packages/package[group=\"#{@call_params[:group_name]}\" and name=\"#{@call_params[:package_name]}\" and version=\"#{@call_params[:package_version]}\"]") if package.to_s != '' = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is uploaded" is_uploaded = true else = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is not uploaded" is_uploaded = false end result = RubyAem::Result.new(, nil) result.data = is_uploaded result end |
#list_all ⇒ Object
List all packages available in AEM instance.
147 148 149 |
# File 'lib/ruby_aem/resources/package.rb', line 147 def list_all() @client.call(self.class, __callee__.to_s, @call_params) end |
#replicate ⇒ Object
Replicate the package. Package will then be added to replication agents.
89 90 91 |
# File 'lib/ruby_aem/resources/package.rb', line 89 def replicate() @client.call(self.class, __callee__.to_s, @call_params) end |
#update(filter) ⇒ Object
Update the package with specific filter.
example: [href="http://">root”:“/apps/geometrixx”,“rules”:[],“root”:“/apps/geometrixx-common”,“rules”:</a>]
54 55 56 57 |
# File 'lib/ruby_aem/resources/package.rb', line 54 def update(filter) @call_params[:filter] = filter @client.call(self.class, __callee__.to_s, @call_params) end |
#upload(file_path, opts = { force: true }) ⇒ Object
Upload the package without waiting until the package status states it is uploaded.
-
force: if false then a package file will not be uploaded when the package already exists with the same group, name, and version, default is true (will overwrite existing package file)
108 109 110 111 112 113 114 115 |
# File 'lib/ruby_aem/resources/package.rb', line 108 def upload(file_path, opts = { force: true }) @call_params[:file_path] = file_path @call_params = @call_params.merge(opts) @client.call(self.class, __callee__.to_s, @call_params) end |
#upload_wait_until_ready(file_path, opts = { force: true, _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object
Upload the package and wait until the package status states it is uploaded.
-
force: if false then a package file will not be uploaded when the package already exists with the same group, name, and version, default is true (will overwrite existing package file)
-
_retries: retries library's options (www.rubydoc.info/gems/retries/0.0.5#Usage), restricted to max_trie, base_sleep_seconds, max_sleep_seconds
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/ruby_aem/resources/package.rb', line 201 def upload_wait_until_ready(file_path, opts = { force: true, _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) opts[:force] ||= true opts[:_retries] ||= {} opts[:_retries][:max_tries] ||= 30 opts[:_retries][:base_sleep_seconds] ||= 2 opts[:_retries][:max_sleep_seconds] ||= 2 # ensure integer retries setting (Puppet 3 passes numeric string) opts[:_retries][:max_tries] = opts[:_retries][:max_tries].to_i opts[:_retries][:base_sleep_seconds] = opts[:_retries][:base_sleep_seconds].to_i opts[:_retries][:max_sleep_seconds] = opts[:_retries][:max_sleep_seconds].to_i result = upload(file_path, opts) with_retries(:max_tries => opts[:_retries][:max_tries], :base_sleep_seconds => opts[:_retries][:base_sleep_seconds], :max_sleep_seconds => opts[:_retries][:max_sleep_seconds]) { |retries_count| check_result = is_uploaded() puts 'Upload check #%d: %s - %s' % [retries_count, check_result.data, check_result.] if check_result.data == false raise StandardError.new(check_result.) end } result end |