Forum Discussion
Narendra_26827
Jul 20, 2011Nimbostratus
iRule to retry with modulus operator
Hi, We have 4 pools and we are redirecting the request to each pool by calculating modulus of crc32 value of an http header id. I have written the following iRule for that : In http header we...
Narendra_26827
Jul 21, 2011Nimbostratus
I have created the following iRule. The active member list order is always different during every event. Can we set it to a proper order? does my below logic of unsetting variables which stores active members list will work?
when HTTP_REQUEST {
set uri [HTTP::uri]
if { [string tolower $uri] contains "/api/gateway" or [string tolower $uri] contains "/api/channel" or [string tolower $uri] contains "/api/space" }
{
set orgid [crc32 [HTTP::header objectId]]
set key [expr $orgid % [active_members default_pool]]
set default_member [active_members -list default_pool]
set channel_member [active_members -list channel-pool]
set gateway_member [active_members -list gateway-pool]
set space_member [active_members -list space-pool]
log "CRC32 value $orgid"
log "Mod value $key"
switch -glob [string tolower $uri] {
"/api/channel*" {
log "[lindex [lindex $channel_member $key] 0] [lindex [lindex $channel_member $key] 1]"
pool channel-pool member [lindex [lindex $channel_member $key] 0] [lindex [lindex $channel_member $key] 1]
unset channel_member
}
"/api/space*" {
log "[lindex [lindex $space_member $key] 0] [lindex [lindex $space_member $key] 1]"
pool space-pool member [lindex [lindex $space_member $key] 0] [lindex [lindex $space_member $key] 1]
unset space_member
}
"/api/gateway*" {
log "[lindex [lindex $gateway_member $key] 0] [lindex [lindex $gateway_member $key] 1]"
pool gateway-pool member [lindex [lindex $gateway_member $key] 0] [lindex [lindex $gateway_member $key] 1]
unset gateway_member
}
default {
log "[lindex [lindex $channel_member $key] 0] [lindex [lindex $channel_member $key] 1]"
pool default_pool member [lindex [lindex $default_member $key] 0] [lindex [lindex $default_member $key] 1]
unset default_member
}
}
}
}
when LB_FAILED {
set uri [HTTP::uri]
if { [HTTP::header exists "objectId"] }
{
set orgid_new [crc32 [HTTP::header objectId]]
set newkey [expr $orgid_new % [active_members default_pool]]
set default_member_new [active_members -list default_pool]
set channel_member_new [active_members -list channel-pool]
set gateway_member_new [active_members -list gateway-pool]
set space_member_new [active_members -list space-pool]
switch -glob [string tolower $uri] {
"/api/channel*" {
log "[lindex [lindex $channel_member_new $newkey] 0] [lindex [lindex $channel_member_new $newkey] 1]"
LB::reselect pool channel-pool member [lindex [lindex $channel_member_new $newkey] 0] [lindex [lindex $channel_member_new $newkey] 1]
unset channel_member_new
}
"/api/space*" {
log "[lindex [lindex $space_member_new $newkey] 0] [lindex [lindex $space_member_new $newkey] 1]"
LB::reselect pool space-pool member [lindex [lindex $space_member_new $newkey] 0] [lindex [lindex $space_member_new $newkey] 1]
unset space_member_new
}
"/api/gateway*" {
log "[lindex [lindex $gateway_member_new $newkey] 0] [lindex [lindex $gateway_member_new $newkey] 1]"
LB::reselect pool gateway-pool member [lindex [lindex $gateway_member_new $newkey] 0] [lindex [lindex $gateway_member_new $newkey] 1]
unset gateway_member_new
}
default {
log "[lindex [lindex $default_member_new $newkey] 0] [lindex [lindex $default_member_new $newkey] 1]"
LB::reselect pool default_pool member [lindex [lindex $default_member_new $newkey] 0] [lindex [lindex $default_member_new $newkey] 1]
unset default_member_new
}
}
}
}
If any body can provide a hint or suggestion. Thanks.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects