Class: RubyAem::Resources::Aem

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_aem/resources/aem.rb

Overview

AEM class contains API calls related to managing the AEM instance itself.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Object

Initialise an AEM instance.

Parameters:

  • client

    RubyAem::Client



26
27
28
29
30
# File 'lib/ruby_aem/resources/aem.rb', line 26

def initialize(client)
  @client = client
  @call_params = {
  }
end

Instance Method Details

#get_aem_health_check(opts = {}) ⇒ Object

Retrieve AEM Health Check. This is a custom API and requires github.com/shinesolutions/aem-healthcheck to be installed.

Parameters:

  • tags

    comma separated tags

  • combine_tags_or

Returns:

  • RubyAem::Result



47
48
49
50
# File 'lib/ruby_aem/resources/aem.rb', line 47

def get_aem_health_check(opts = {})
  @call_params = @call_params.merge(opts)
  @client.call(self.class, __callee__.to_s, @call_params)
end

#get_aem_health_check_wait_until_ok(opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object

Retrieve AEM health check with retries until its status is OK.

Parameters:

  • opts (defaults to: { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } })

    optional parameters:

Returns:

  • RubyAem::Result



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ruby_aem/resources/aem.rb', line 99

def get_aem_health_check_wait_until_ok(
  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 = nil
  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|
    begin
      result = get_aem_health_check(tags: opts[:tags], combine_tags_or: opts[:combine_tags_or])
      is_ok = true
      result.data.each { |check|
        if check['status'] != 'OK'
          is_ok = false
          break
        end
      }
      if is_ok == false
        puts format('Retrieve AEM Health Check attempt #%d: %s but not ok yet', retries_count, result.message)
        raise StandardError.new(result.message)
      else
        puts format('Retrieve AEM Health Check attempt #%d: %s and ok', retries_count, result.message)
      end
    rescue RubyAem::Error => err
      puts format('Retrieve AEM Health Check attempt #%d: %s', retries_count, err.message)
      raise StandardError.new(err.message)
    end
  }
  result
end

#get_agents(run_mode) ⇒ Object

List the name of all agents under /etc/replication.

Parameters:

  • run_mode

    AEM run mode: author or publish

Returns:

  • RubyAem::Result



147
148
149
150
# File 'lib/ruby_aem/resources/aem.rb', line 147

def get_agents(run_mode)
  @call_params[:run_mode] = run_mode
  @client.call(self.class, __callee__.to_s, @call_params)
end

#get_install_statusObject

Retrieve AEM install status.

Returns:

  • RubyAem::Result



155
156
157
# File 'lib/ruby_aem/resources/aem.rb', line 155

def get_install_status
  @client.call(self.class, __callee__.to_s, @call_params)
end

#get_install_status_wait_until_finished(opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object

Retrieve AEM install status with retries until its status is finished

Parameters:

  • opts (defaults to: { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } })

    optional parameters:

Returns:

  • RubyAem::Result



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/ruby_aem/resources/aem.rb', line 164

def get_install_status_wait_until_finished(
  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 = nil
  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|
    begin
      result = get_install_status
      item_count = result.response.body.status.item_count
      if result.response.body.status.finished == true && item_count.zero?
        puts format('Retrieve AEM install status attempt #%d: %s and finished', retries_count, result.message)
      else
        puts format('Retrieve AEM install status attempt #%d: %s but not finished yet, still installing %d package(s)', retries_count, result.message, item_count)
        raise StandardError.new(result.message)
      end
    rescue RubyAem::Error => err
      puts format('Retrieve AEM install status attempt #%d: %s', retries_count, err.message)
      raise StandardError.new(err.message)
    end
  }
  result
end

#get_login_pageObject

Retrieve AEM login page.

Returns:

  • RubyAem::Result



35
36
37
# File 'lib/ruby_aem/resources/aem.rb', line 35

def 
  @client.call(self.class, __callee__.to_s, @call_params)
end

#get_login_page_wait_until_ready(opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object

Retrieve AEM login page with retries until it is successful.

Parameters:

  • opts (defaults to: { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } })

    optional parameters:

Returns:

  • RubyAem::Result



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ruby_aem/resources/aem.rb', line 57

def (
  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 = nil
  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|
    begin
      result = 
      if result.response.body !~ /QUICKSTART_HOMEPAGE/
        puts format('Retrieve login page attempt #%d: %s but not ready yet', retries_count, result.message)
        raise StandardError.new(result.message)
      else
        puts format('Retrieve login page attempt #%d: %s and ready', retries_count, result.message)
      end
    rescue RubyAem::Error => err
      puts format('Retrieve login page attempt #%d: %s', retries_count, err.message)
      raise StandardError.new(err.message)
    end
  }
  result
end