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.
-
#build_wait_until_ready(opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object
Build the package and wait until the package status states it is built (exists and not empty).
-
#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.
-
#exists ⇒ Object
Check if this package exists.
-
#get_filter ⇒ Object
Get the package filter value.
-
#get_versions ⇒ Object
Find all versions of the package Result data should contain an array of version values, empty array if there's none.
-
#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_built ⇒ Object
Check if this package is built.
-
#is_empty ⇒ Object
Check if this package is empty (has size 0).
-
#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.
-
#uninstall ⇒ Object
Uninstall 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.
30 31 32 33 34 35 36 37 |
# File 'lib/ruby_aem/resources/package.rb', line 30 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
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ruby_aem/resources/package.rb', line 139 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.
66 67 68 |
# File 'lib/ruby_aem/resources/package.rb', line 66 def build @client.call(self.class, __callee__.to_s, @call_params) end |
#build_wait_until_ready(opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object
Build the package and wait until the package status states it is built (exists and not empty).
-
_retries: retries library's options (www.rubydoc.info/gems/retries/0.0.5#Usage), restricted to max_tries, base_sleep_seconds, max_sleep_seconds
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/ruby_aem/resources/package.rb', line 401 def build_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 = build 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_built puts format('Build check #%d: %s - %s', retries_count, check_result.data, check_result.) if check_result.data == false raise StandardError.new(check_result.) end } result end |
#create ⇒ Object
Create the package.
42 43 44 |
# File 'lib/ruby_aem/resources/package.rb', line 42 def create @client.call(self.class, __callee__.to_s, @call_params) end |
#delete ⇒ Object
Delete the package.
59 60 61 |
# File 'lib/ruby_aem/resources/package.rb', line 59 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_tries, base_sleep_seconds, max_sleep_seconds
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/ruby_aem/resources/package.rb', line 366 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 format('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.
101 102 103 104 |
# File 'lib/ruby_aem/resources/package.rb', line 101 def download(file_path) @call_params[:file_path] = file_path @client.call(self.class, __callee__.to_s, @call_params) end |
#exists ⇒ Object
Check if this package exists. True result data indicates that the package exists, false otherwise.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/ruby_aem/resources/package.rb', line 182 def exists 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]} exists" exists = true else = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} does not exist" exists = false end result = RubyAem::Result.new(, nil) result.data = exists result end |
#get_filter ⇒ Object
Get the package filter value. Filter value is stored as result data as an array of paths.
127 128 129 |
# File 'lib/ruby_aem/resources/package.rb', line 127 def get_filter @client.call(self.class, __callee__.to_s, @call_params) end |
#get_versions ⇒ Object
Find all versions of the package Result data should contain an array of version values, empty array if there's none.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/ruby_aem/resources/package.rb', line 161 def get_versions packages = list_all.data package_versions = packages.xpath("//packages/package[group=\"#{@call_params[:group_name]}\" and name=\"#{@call_params[:package_name]}\"]") versions = [] package_versions.each do |package| version = package.xpath('version/text()') versions.push(version.to_s) if version.to_s != '' end = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} has #{versions.length} version(s)" result = RubyAem::Result.new(, nil) result.data = versions result 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
75 76 77 78 79 80 |
# File 'lib/ruby_aem/resources/package.rb', line 75 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_tries, base_sleep_seconds, max_sleep_seconds
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/ruby_aem/resources/package.rb', line 331 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 format('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_built ⇒ Object
Check if this package is built. The indicator whether a package is built is when it exists and is not empty. True result data indicates that the package is built, false otherwise.
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/ruby_aem/resources/package.rb', line 264 def is_built exists_result = exists if exists_result.data == true is_empty_result = is_empty if is_empty_result.data == false = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is built" is_built = true else = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is not built because it is empty" is_built = false end else = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is not built because it does not exist" is_built = false end result = RubyAem::Result.new(, nil) result.data = is_built result end |
#is_empty ⇒ Object
Check if this package is empty (has size 0). True result data indicates that the package is empty, false otherwise.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/ruby_aem/resources/package.rb', line 242 def is_empty 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]}\"]") size = package.xpath('size/text()').to_s.to_i if size.zero? = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is empty" is_empty = true else = "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is not empty" is_empty = false end result = RubyAem::Result.new(, nil) result.data = is_empty result end |
#is_installed ⇒ Object
Check if this package is installed. True result data indicates that the package is installed, false otherwise.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/ruby_aem/resources/package.rb', line 220 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 !['', '<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. The indicator whether a package is uploaded is when it exists True result data indicates that the package is uploaded, false otherwise.
203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/ruby_aem/resources/package.rb', line 203 def is_uploaded result = exists result. = if result.data == true "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is uploaded" else "Package #{@call_params[:group_name]}/#{@call_params[:package_name]}-#{@call_params[:package_version]} is not uploaded" end result end |
#list_all ⇒ Object
List all packages available in AEM instance.
153 154 155 |
# File 'lib/ruby_aem/resources/package.rb', line 153 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.
93 94 95 |
# File 'lib/ruby_aem/resources/package.rb', line 93 def replicate @client.call(self.class, __callee__.to_s, @call_params) end |
#uninstall ⇒ Object
Uninstall the package.
85 86 87 |
# File 'lib/ruby_aem/resources/package.rb', line 85 def uninstall @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>]
51 52 53 54 |
# File 'lib/ruby_aem/resources/package.rb', line 51 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)
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ruby_aem/resources/package.rb', line 112 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_tries, base_sleep_seconds, max_sleep_seconds
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/ruby_aem/resources/package.rb', line 293 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 format('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 |