|
| 1 | +# == Define: aem::dispatcher::farm |
| 2 | +# |
| 3 | +# Configure a Dispatcher instance. |
| 4 | +define aem::dispatcher::farm( |
| 5 | + $ensure = 'present', |
| 6 | + $allow_authorized = undef, |
| 7 | + $allowed_clients = $::aem::dispatcher::params::allowed_clients, |
| 8 | + $cache_headers = $::aem::dispatcher::params::cache_headers, |
| 9 | + $cache_rules = $::aem::dispatcher::params::cache_rules, |
| 10 | + $cache_ttl = undef, |
| 11 | + $client_headers = $::aem::dispatcher::params::client_headers, |
| 12 | + $docroot = undef, |
| 13 | + $failover = undef, |
| 14 | + $filters = $::aem::dispatcher::params::filters, |
| 15 | + $grace_period = undef, |
| 16 | + $health_check_url = undef, |
| 17 | + $ignore_parameters = undef, |
| 18 | + $invalidate = $::aem::dispatcher::params::invalidate, |
| 19 | + $invalidate_handler = undef, |
| 20 | + $propagate_synd_post = undef, |
| 21 | + $renders = $::aem::dispatcher::params::renders, |
| 22 | + $retries = undef, |
| 23 | + $retry_delay = undef, |
| 24 | + $serve_stale = $::aem::dispatcher::params::serve_stale, |
| 25 | + $session_management = undef, |
| 26 | + $stat_file = undef, |
| 27 | + $stat_files_level = undef, |
| 28 | + $statistics = undef, |
| 29 | + $sticky_connections = undef, |
| 30 | + $unavailable_penalty = undef, |
| 31 | + $vanity_urls = undef, |
| 32 | + $virtualhosts = $::aem::dispatcher::params::virtualhosts |
| 33 | +) { |
| 34 | + |
| 35 | + # Required dispatcher class because it is used by parameter defaults |
| 36 | + if ! defined(Class['aem::dispatcher']) { |
| 37 | + fail('You must include the aem::dispatcher base class before using any dispatcher class or defined resources') |
| 38 | + } |
| 39 | + |
| 40 | + validate_re($ensure, '^(present|absent)$', "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.") |
| 41 | + |
| 42 | + if $allow_authorized { |
| 43 | + validate_integer($allow_authorized, 1, 0) |
| 44 | + } |
| 45 | + |
| 46 | + if is_array($allowed_clients) { |
| 47 | + validate_hash($allowed_clients[0]) |
| 48 | + $_allowed_clients = $allowed_clients |
| 49 | + } else { |
| 50 | + validate_hash($allowed_clients) |
| 51 | + $_allowed_clients = [$allowed_clients] |
| 52 | + } |
| 53 | + |
| 54 | + if $cache_headers { |
| 55 | + if is_array($cache_headers) { |
| 56 | + $_cache_headers = $cache_headers |
| 57 | + } else { |
| 58 | + $_cache_headers = [$cache_headers] |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + if is_array($cache_rules) { |
| 63 | + validate_hash($cache_rules[0]) |
| 64 | + $_cache_rules = $cache_rules |
| 65 | + } else { |
| 66 | + validate_hash($cache_rules) |
| 67 | + $_cache_rules = [$cache_rules] |
| 68 | + } |
| 69 | + |
| 70 | + if $cache_ttl { |
| 71 | + validate_integer($cache_ttl, 1, 0) |
| 72 | + } |
| 73 | + |
| 74 | + if is_array($client_headers) { |
| 75 | + $_client_headers = $client_headers |
| 76 | + } else { |
| 77 | + $_client_headers = [$client_headers] |
| 78 | + } |
| 79 | + |
| 80 | + validate_absolute_path($docroot) |
| 81 | + |
| 82 | + if $failover { |
| 83 | + validate_integer($failover, 1, 0) |
| 84 | + } |
| 85 | + |
| 86 | + if is_array($filters) { |
| 87 | + validate_hash($filters[0]) |
| 88 | + $_filters = $filters |
| 89 | + } else { |
| 90 | + validate_hash($filters) |
| 91 | + $_filters = [$filters] |
| 92 | + } |
| 93 | + |
| 94 | + if $grace_period { |
| 95 | + validate_integer($grace_period, undef, 1) |
| 96 | + } |
| 97 | + |
| 98 | + if $health_check_url { |
| 99 | + validate_string($health_check_url) |
| 100 | + } |
| 101 | + |
| 102 | + if $ignore_parameters { |
| 103 | + if is_array($ignore_parameters) { |
| 104 | + validate_hash($ignore_parameters[0]) |
| 105 | + $_ignore_parameters = $ignore_parameters |
| 106 | + } else { |
| 107 | + validate_hash($ignore_parameters) |
| 108 | + $_ignore_parameters = [$ignore_parameters] |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + if is_array($invalidate) { |
| 113 | + validate_hash($invalidate[0]) |
| 114 | + $_invalidate = $invalidate |
| 115 | + } else { |
| 116 | + validate_hash($invalidate) |
| 117 | + $_invalidate = [$invalidate] |
| 118 | + } |
| 119 | + |
| 120 | + if $invalidate_handler { |
| 121 | + validate_absolute_path($invalidate_handler) |
| 122 | + } |
| 123 | + |
| 124 | + if $propagate_synd_post { |
| 125 | + validate_integer($propagate_synd_post, 1, 0) |
| 126 | + } |
| 127 | + |
| 128 | + if is_array($renders) { |
| 129 | + validate_hash($renders[0]) |
| 130 | + $_renders = $renders |
| 131 | + } else { |
| 132 | + validate_hash($renders) |
| 133 | + $_renders = [$renders] |
| 134 | + } |
| 135 | + |
| 136 | + if $retries { |
| 137 | + validate_integer($retries, undef, 1) |
| 138 | + } |
| 139 | + |
| 140 | + if $retry_delay { |
| 141 | + validate_integer($retry_delay, undef, 1) |
| 142 | + } |
| 143 | + |
| 144 | + if $serve_stale { |
| 145 | + validate_integer($serve_stale, 1, 0) |
| 146 | + } |
| 147 | + |
| 148 | + if $session_management { |
| 149 | + if $allow_authorized == 1 { |
| 150 | + fail('Allow authorized and session management are mutually exclusive.') |
| 151 | + } |
| 152 | + validate_hash($session_management) |
| 153 | + if !has_key($session_management, 'directory') { |
| 154 | + fail('Session management directory is not specified.') |
| 155 | + } else { |
| 156 | + validate_absolute_path($session_management['directory']) |
| 157 | + } |
| 158 | + if has_key($session_management, 'encode') { |
| 159 | + validate_re($session_management['encode'], '^(md5|hex)$', |
| 160 | + "${session_management['encode']} is not supported for session_management['encode']. Allowed values are 'md5' and 'hex'.") |
| 161 | + } |
| 162 | + if has_key($session_management, 'timeout') { |
| 163 | + validate_integer($session_management['timeout'], undef, 0) |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + if $stat_file { |
| 168 | + validate_absolute_path($stat_file) |
| 169 | + } |
| 170 | + |
| 171 | + if $stat_files_level { |
| 172 | + validate_integer($stat_files_level, undef, 0) |
| 173 | + } |
| 174 | + |
| 175 | + if $statistics { |
| 176 | + if is_array($statistics) { |
| 177 | + validate_hash($statistics[0]) |
| 178 | + $_statistics = $statistics |
| 179 | + } else { |
| 180 | + validate_hash($statistics) |
| 181 | + $_statistics = [$statistics] |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + if $sticky_connections { |
| 186 | + if is_array($sticky_connections) { |
| 187 | + validate_string($sticky_connections[0]) |
| 188 | + } else { |
| 189 | + validate_string($sticky_connections) |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + if $unavailable_penalty { |
| 194 | + validate_integer($unavailable_penalty, undef, 1) |
| 195 | + } |
| 196 | + |
| 197 | + if $vanity_urls { |
| 198 | + validate_hash($vanity_urls) |
| 199 | + if !has_key($vanity_urls, 'file') { |
| 200 | + fail('Vanity Urls cache file is not specified.') |
| 201 | + } else { |
| 202 | + validate_absolute_path($vanity_urls['file']) |
| 203 | + validate_integer($vanity_urls['delay'], undef, 0) |
| 204 | + } |
| 205 | + } |
| 206 | + |
| 207 | + if !is_array($virtualhosts) { |
| 208 | + $_virtualhosts = [$virtualhosts] |
| 209 | + } else { |
| 210 | + $_virtualhosts = $virtualhosts |
| 211 | + } |
| 212 | + |
| 213 | + $_line_start = ' $include "dispatcher.' |
| 214 | + $_line_end = '.any"' |
| 215 | + |
| 216 | + if $ensure == 'present' { |
| 217 | + file { "${::aem::dispatcher::params::farm_path}/dispatcher.${name}.any" : |
| 218 | + ensure => $ensure, |
| 219 | + content => template("${module_name}/dispatcher/dispatcher.any.erb"), |
| 220 | + } |
| 221 | + file_line { "include ${name}.any" : |
| 222 | + ensure => $ensure, |
| 223 | + after => '/farms \{', |
| 224 | + line => "${_line_start}${name}${_line_end}", |
| 225 | + match => "${_line_start}${name}${_line_end}", |
| 226 | + path => "${::aem::dispatcher::params::farm_path}/${::aem::dispatcher::config_file}", |
| 227 | + require => File["${::aem::dispatcher::params::farm_path}/${::aem::dispatcher::config_file}"], |
| 228 | + } |
| 229 | + |
| 230 | + } else { |
| 231 | + |
| 232 | + file_line { "include ${name}.any" : |
| 233 | + ensure => $ensure, |
| 234 | + path => "${::aem::dispatcher::params::farm_path}/${::aem::dispatcher::config_file}", |
| 235 | + line => "${_line_start}${name}${_line_end}", |
| 236 | + match => "${_line_start}${name}${_line_end}", |
| 237 | + } |
| 238 | + |
| 239 | + file { "${::aem::dispatcher::params::farm_path}/dispatcher.${name}.any" : |
| 240 | + ensure => $ensure, |
| 241 | + require => File_line["include ${name}.any"], |
| 242 | + } |
| 243 | + } |
| 244 | +} |
0 commit comments